So, I have this piece of code in a static method Camelize
return strtr(ucwords(strtr($id, array('_' => ' ', '.' => '_ ', '\\' => '_ '))), array(' ' => ''));
It is just a camel.
I have about 211 thousand records, closed loop iteration. These entries contain a few words that I need for a camel, the longest word can be about 10 characters, simple peasy, but with some xhprof tests, I came to the conclusion that camelize is not a good idea if you need speed.
XHProf with camelize : 313,866,303 microseconds (~ 5 minutes)
- 19,268,795 calls
- On Wall time 228 658 500
- ICpu: 81.3%
XHProf without camelize : 55,099,811 microseconds (<1min)
The purpose of this script is to set values for class properties.
The property may be protected $myVarthat is camelized.
underscore ( ) ( ). my_var => foo
, camelize, -
$this->$camelizedProperty = $value
, , - , , 4 , , , , .
UPDATE
microtime, , ...
:
strtr(ucwords(strtr($word, array('_' => ' ', '.' => '_ ', '\\' => '_ '))), array(' ' => ''))lcfirst(str_replace(" ", "", ucwords(strtr($word, "_-", " "))))str_replace(" ", "", ucwords(strtr($word, "_-", " ")))
~ 100 :
@RST , str_replace 18% , , ( )
20- , xhprof, :
- 313 (~ 5 )
- 152 (~ 2,5 )
- 158 (~ 2,5 )
, lcfirst script ( , ).
, , , , .