PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: (int) vs. intval

the semantic difference here is only that intval() can convert bases, whereas (int) cannot.

View test history (3) Run this test again Return to test menu

Result: Discarded

The test labeled "intval()" was the faster by 0.0415 seconds, (4.593% faster)

intval() 100%
(int) 95.407%

The intval() test took 0.8618 seconds.
The (int) test took 0.9033 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 196,178 loops for a total of 3,923,560 runs.

  • Line execution difference (0.000011) milliseconds.
  • Avg difference (2.075) milliseconds per 196,178 loops.
  • Total difference 41.49 milliseconds for 3,923,560 loops

The iteration variablity for Code 1 was (7.7977) milliseconds and Code 2 was (6.3620) milliseconds. The lower and the closer together there values are the more accurate the results are.

Code

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

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

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

for ($j = 0; $j < 100; $j++)
	$i = intval('42 ');

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