PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: rand vs. mt_rand

No Description

Run this test again Return to test menu

Result: Discarded

The test labeled "mt_rand()" was the faster by 0.0764 seconds, (6.152% faster)

mt_rand() 100%
rand() 93.848%

The mt_rand() test took 1.1661 seconds.
The rand() test took 1.2425 seconds.


Each test case ran 20 random code order iterations consisting of 262,021 loops for a total of 5,240,420 runs.

  • Line execution difference (0.000015) milliseconds.
  • Avg difference (3.822) milliseconds per 262,021 loops.
  • Total difference 76.44 milliseconds for 5,240,420 loops

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


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

$GLOBALS['dummy'] = rand(0, 1000);

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

$GLOBALS['dummy'] = mt_rand(0, 1000);

Running: Linux (x86_64:1 GB) PHP (