root/trunk/tests/benchmark_str_replace.php

Revision 2, 1.0 kB (checked in by schst, 5 years ago)

initial import on new server

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?PHP
2 /**
3  * simple benchmark to check whether looking for a string to replace is faster
4  * than replacing it directly. It needs the PEAR::Benchmark_Timer class.
5  *
6  * $Id$
7  *
8  * @package        patForms
9  * @subpackage    Tests
10  * @author        Sebastian Mordziol <argh@php-tool.net>
11  */
12  
13    /**
14     * uses the PEAR::Benchmark_Timer class
15     */
16     require_once 'Benchmark/Timer.php';
17
18     $string    =    'RadioGroup_Option';
19     $timer    =    &new Benchmark_Timer();
20     
21     $timer->start();
22
23     // strpos
24     for( $i = 1; $i <= 5000; $i++ )
25     {
26         if( strpos( $string, '_' ) !== false )
27         {
28         }
29     }
30     $timer->setMarker( 'strpos' );
31
32     // strstr
33     for( $i = 1; $i <= 5000; $i++ )
34     {
35         if( strstr( $string, '_' ) !== false )
36         {
37         }
38     }
39     $timer->setMarker( 'strstr' );
40
41     // stristr
42     for( $i = 1; $i <= 5000; $i++ )
43     {
44         if( stristr( $string, '_' ) !== false )
45         {
46         }
47     }
48     $timer->setMarker( 'stristr' );
49
50     // str_replace
51     for( $i = 1; $i <= 5000; $i++ )
52     {
53         str_replace( '_', '/', $string );
54     }
55     $timer->setMarker( 'str_replace' );
56
57     $timer->stop();
58     $timer->display();
59 ?>
Note: See TracBrowser for help on using the browser.