Zoals al aangegeven in het artikel op Pankaj Kumar’s Weblog: het geheugenverbruik bij integers is niet zoals verwacht bij het gebruik van verschillende datatypen.

Omdat zijn weblog een extra login benodigd, ben ik zo vrij geweest om mijn resultaten op diverse machines hier te publiceren.

Pankaj gaf de volgende benchmark op zijn memtest.php:
[pankaj@fc7-dev ~]$ php -v
PHP 5.2.4 (cli) (built: Sep 18 2007 08:50:58)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
[pankaj@fc7-dev ~]$ php -C memtest.php
Space Used by int_array: 72492
Space Used by str_array: 88264
Space Used by arr_array: 160292
Space Used by obj_array: 180316
Space Used by arr2_array: 304344
Space Used by obj2_array: 349144
[pankaj@fc7-dev ~]$

Mijn eigen testresultaten:

three:~# php -v
PHP 5.2.5 (cli) (built: Feb 8 2008 12:46:05)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
with the ionCube PHP Loader v3.1.32, Copyright (c) 2002-2007, by ionCube Ltd.
three:~# php -C memtest.php
Space Used by int_array: 72488
Space Used by str_array: 88264
Space Used by arr_array: 160304
Space Used by obj_array: 180304
Space Used by arr2_array: 304336
Space Used by obj2_array: 349136

daniel@retrogres:~$ php -v
PHP 4.4.7-0.dotdeb.0 with Suhosin-Patch 0.9.6 (cli) (built: May 9 2007 16:38:02)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
daniel@retrogres:~$ php -C /var/www/memtest.php
Space Used by int_array: 60280
Space Used by str_array: 68248
Space Used by arr_array: 132256
Space Used by obj_array: 132256
Space Used by arr2_array: 244256
Space Used by obj2_array: 244408

Zoals te zien is de versie van je PHP-installatie dus ook nog van invloed. PHP4 (4.4.7-0) is het zuinigst met de resources…