PHP Benchmarks

Performance comparison of PHP code alternatives.

Test: strtr vs. str_replace on long strings

No Description

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

Result: Discarded

The test labeled "strtr()" was the faster by 0.0035 seconds, (0.665% faster)

strtr() 100%
str_replace() 99.335%

The strtr() test took 0.5278 seconds.
The str_replace() test took 0.5313 seconds.

Nitty-Gritty

Each test case ran 20 random code order iterations consisting of 130,450 loops for a total of 2,609,000 runs.

  • Line execution difference (0.000001) milliseconds.
  • Avg difference (0.177) milliseconds per 130,450 loops.
  • Total difference 3.53 milliseconds for 2,609,000 loops

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

Code

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

$GLOBALS['i']++;

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

$GLOBALS['asdfasdfasdfjjskljdfklajlsdjfajskldfjkaskjdkfjaskldjfklasjkldfjklasdj']++;

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