PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: strftime vs. localtime

No Description

Run this test again Return to test menu

Result: Discarded

The test labeled "localtime()" was the faster by 0.0402 seconds, (5.742% faster)

localtime() 100%
strftime() 94.258%

The localtime() test took 0.6605 seconds.
The strftime() test took 0.7008 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 140,312 loops for a total of 2,806,240 runs.

  • Line execution difference (0.000014) milliseconds.
  • Avg difference (2.012) milliseconds per 140,312 loops.
  • Total difference 40.24 milliseconds for 2,806,240 loops

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

Code

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

for ($i = 0; $i < 100; $i++)
	$GLOBALS['dummy'] = (int) strftime('%d', $GLOBALS['t']);

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

for ($i = 0; $i < 100; $i++)
{
	$temp = localtime($GLOBALS['t'], true);
	$GLOBALS['dummy'] = $temp['tm_mday'];
}

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