PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: substr on short vs. long strings

No Description

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

Result: Discarded

The test labeled "short" was the faster by 0.0158 seconds, (1.827% faster)

short 100%
long (x200) 98.173%

The short test took 0.8482 seconds.
The long (x200) test took 0.864 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 237,806 loops for a total of 4,756,120 runs.

  • Line execution difference (0.000003) milliseconds.
  • Avg difference (0.789) milliseconds per 237,806 loops.
  • Total difference 15.79 milliseconds for 4,756,120 loops

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

Code

The first test, "short", was:

for ($j = 0; $j < 100; $j++)
	$GLOBALS['dummy2'] = substr($GLOBALS['dummy_short'], 10, 10);

The second test, "long (x200)", was:

for ($j = 0; $j < 100; $j++)
	$GLOBALS['dummy2'] = substr($GLOBALS['dummy_long'], 10, 10);

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