Warning: Division by zero in /var/customers/webs/stc/benchmark/index.php on line 256 Test: (int) vs. settype

PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: (int) vs. settype()

If you already have a variable, logic tells us that changing is type might be faster than creating a new value (which a cast does.) But, is this true?

Run Again Test Menu

Result

Unfortunately, no history for this test is available.

Code

The first test, "(int)", was:

for ($j = 0; $j < 100; $j++)
{
	$i = '42 ';
	$i = (int) $i;
}

The second test, "settype()", was:

for ($j = 0; $j < 100; $j++)
{
	$i = '42 ';
	settype($i, 'int');
}

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