WordPress.org

Make WordPress Core

Ticket #19100: wp-formatting-timer.php

File wp-formatting-timer.php, 1.3 KB (added by mbijon, 2 years ago)

Testing for speed of replacement methods

Line 
1<?php
2
3// Color via GET
4$color_init = ( isset($_GET['color']) ) ? $_GET['color'] : "%23123456";
5$repeat = ( isset($_GET['repeat']) && is_numeric($_GET['repeat']) ) ? $_GET['repeat'] : 2000000;
6
7
8// For the record
9echo "Looping $repeat times<br /><br />";
10
11
12// Time the strpos() way
13$time_a1 = microtime(true);
14echo "Start strpos(): $time_a1<br />";
15
16for ( $i = 0; $i < $repeat; $i++ ){
17    if ( 0 === strpos( $color_init, '#' ) )
18        $color = substr( $color_init, 1 );
19    elseif ( 0 === strpos( $color_init, '%23' ) )
20        $color = substr( $color_init, 3 );
21    else $color = $color_init;
22}
23
24echo "Final strpos() color: $color<br />";
25$time_a2 = microtime(true);
26echo "End strpos(): $time_a2<br />";
27echo "Total time: " . ($time_a2 - $time_a1) . "<br /><br />";
28
29
30// Time the trim() way
31$time_b1 = microtime(true);
32echo "Start trim(): $time_b1<br />";
33
34for ( $i = 0; $i < $repeat; $i++ ){
35    //$color = trim( urldecode( $color_init ), "#" ); //used as 2nd trim
36    $color = trim( urldecode( $color_init ), "# \t\r\n\0\x0B" ); //replace existing diff's trim
37    //$color = trim( urldecode( trim( $color_init ) ), "#" ); //double trim
38}
39
40echo "Final trim() color: $color<br />";
41$time_b2 = microtime(true);
42echo "End trim(): $time_b2<br />";
43echo "Total time: " . ($time_b2 - $time_b1) . "<br /><br />";