Warning: Division by zero in /var/customers/webs/stc/benchmark/index.php on line 256 Test: set immediately or later

PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: set immediately or later

Is it better to put values inside array() when filling an array or to put values into it later?

Run Again Test Menu

Result

Unfortunately, no history for this test is available.

Code

The first test, "immediate", was:

for ($i = 0; $i < 10; $i++)
	$GLOBALS['dummy2'] = array(
		0 => 'hello',
		1 => 'good bye',
		2 => 'thank you',
		3 => 'sorry',
	);

The second test, "later", was:

for ($i = 0; $i < 10; $i++)
{
	$GLOBALS['dummy2'] = array();
	$GLOBALS['dummy2'][0] = 'hello';
	$GLOBALS['dummy2'][1] = 'good bye';
	$GLOBALS['dummy2'][2] = 'thank you';
	$GLOBALS['dummy2'][3] = 'sorry';
}

Running: Linux (x86_64:1 GB) PHP (7.2.25-1+ubuntu16.04.1+deb.sury.org+1)