PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: is_string vs. Casting

Cast vs is_string

Run this test again Return to test menu

Result: Discarded

The test labeled "Casting" was the faster by 0.0081 seconds, (1.324% faster)

Casting 100%
is_float 98.676%

The Casting test took 0.6009 seconds.
The is_float test took 0.609 seconds.


Each test case ran 20 random code order iterations consisting of 140,583 loops for a total of 2,811,660 runs.

  • Line execution difference (0.000003) milliseconds.
  • Avg difference (0.403) milliseconds per 140,583 loops.
  • Total difference 8.06 milliseconds for 2,811,660 loops

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


The first test, "is_float", was:

$a = is_string($GLOBALS['test']);

The second test, "Casting", was:

$a = (string) $GLOBALS['test'] === $GLOBALS['test'];

Running: Linux (x86_64:1 GB) PHP (