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 (1) Run this test again Return to test menu

Result: Discarded

The test labeled "(int)" was the faster by 0.1038 seconds, (8.477% faster)

(int) 100%
intval() 91.523%

The (int) test took 1.1206 seconds.
The intval() test took 1.2244 seconds.


Each test case ran 20 random code order iterations consisting of 286,202 loops for a total of 5,724,040 runs.

  • Line execution difference (0.000018) milliseconds.
  • Avg difference (5.190) milliseconds per 286,202 loops.
  • Total difference 103.79 milliseconds for 5,724,040 loops

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


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 (