#752: should not use "substr($str, 0, 1)" but "$str[0]"
-------------------------+--------------------------------------------------
 Reporter:  MugeSo       |       Owner:  david 
     Type:  enhancement  |      Status:  new   
 Priority:  normal       |   Milestone:  0.11.1
Component:  _OTHER_      |     Version:  0.11.0
 Severity:  normal       |    Keywords:        
Has_patch:  0            |  
-------------------------+--------------------------------------------------
 In
 src/validator/AgaviDependencyManager.class.php,
 src/controller/AgaviController.class.php and
 src/routing/AgaviRouting.class.php,
 to retrive the first charactor of a string, substr function is used.
 However, in this case, []operator is better.

 benchmark result:
 {{{
 [EMAIL PROTECTED] senna]$ time php -r '$str="aaaaa"; for($i=0; $i < 1000000;
 $i++){ substr($str, 0, 1) == "a";}'

 real    0m3.345s
 user    0m3.320s
 sys     0m0.020s
 [EMAIL PROTECTED] senna]$ time php -r '$str="aaaaa"; for($i=0; $i < 1000000;
 $i++){ $str[0] == "a";}'

 real    0m2.012s
 user    0m1.990s
 sys     0m0.020s

 [EMAIL PROTECTED] senna]$ time php -r '$str="aaaaa"; for($i=0; $i < 1000000;
 $i++){ $str[0];}'

 real    0m0.853s
 user    0m0.850s
 sys     0m0.010s
 [EMAIL PROTECTED] senna]$ time php -r '$str="aaaaa"; for($i=0; $i < 1000000;
 $i++){ substr($str, 0, 1);}'

 real    0m2.585s
 user    0m2.570s
 sys     0m0.010s
 }}}

-- 
Ticket URL: <http://trac.agavi.org/ticket/752>
Agavi <http://www.agavi.org/>
An MVC Framework for PHP5


_______________________________________________
Agavi Tickets Mailing List
[email protected]
http://lists.agavi.org/mailman/listinfo/tickets

Reply via email to