[limb-svn] r6404 - in 3.x/trunk/limb/core: . tests/bench

svn at limb-project.com svn at limb-project.com
Wed Oct 10 02:02:56 MSD 2007


Author: pachanga
Date: 2007-10-10 02:02:56 +0400 (Wed, 10 Oct 2007)
New Revision: 6404
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6404

Modified:
   3.x/trunk/limb/core/common.inc.php
   3.x/trunk/limb/core/tests/bench/object-attr.php
Log:
-- minor optimizations and refactoring

Modified: 3.x/trunk/limb/core/common.inc.php
===================================================================
--- 3.x/trunk/limb/core/common.inc.php	2007-10-09 21:27:41 UTC (rev 6403)
+++ 3.x/trunk/limb/core/common.inc.php	2007-10-09 22:02:56 UTC (rev 6404)
@@ -143,6 +143,10 @@
 
 function lmb_camel_case($str, $ucfirst = true)
 {
+  //if there are no _, why process at all
+  if(strpos($str, '_') === false)
+    return ($ucfirst) ? ucfirst($str) : $str;
+
   $items = explode('_', $str);
   $len = sizeof($items);
   $first = true;
@@ -168,9 +172,11 @@
 
 function lmb_under_scores($str)
 {
+  //caching repeated requests
   static $cache = array();
   if(isset($cache[$str]))
     return $cache[$str];
+
   $items = preg_split('~([A-Z][a-z0-9]+)~', $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
   $res = '';
   foreach($items as $item)

Modified: 3.x/trunk/limb/core/tests/bench/object-attr.php
===================================================================
--- 3.x/trunk/limb/core/tests/bench/object-attr.php	2007-10-09 21:27:41 UTC (rev 6403)
+++ 3.x/trunk/limb/core/tests/bench/object-attr.php	2007-10-09 22:02:56 UTC (rev 6404)
@@ -14,39 +14,46 @@
 $object = new Foo(array('foo' => 'foo'));
 
 for($i=0;$i<1000;$i++)
-  $object->get('heatingUp');
+  $object->get('heating_up');
 
 $mark = microtime(true);
 
 for($i=0;$i<1000;$i++)
   $object->get('foo');
 
-echo "raw getter access: " . (microtime(true) - $mark) . "\n";
+echo "get('foo'): " . (microtime(true) - $mark) . "\n";
 
 $mark = microtime(true);
 
 for($i=0;$i<1000;$i++)
+  $object->get('foo' . $i);
+
+echo "get('fooXXX'): " . (microtime(true) - $mark) . "\n";
+
+$mark = microtime(true);
+
+for($i=0;$i<1000;$i++)
   $object->get('bar');
 
-echo "raw getter access mapped to method: " . (microtime(true) - $mark) . "\n";
+echo "get('bar') => getBar(): " . (microtime(true) - $mark) . "\n";
 
 $mark = microtime(true);
 
 for($i=0;$i<1000;$i++)
   $object->getBar();
 
-echo "static getter access: " . (microtime(true) - $mark) . "\n";
+echo "istance getBar(): " . (microtime(true) - $mark) . "\n";
 
 $mark = microtime(true);
 
 for($i=0;$i<1000;$i++)
   $object->getFoo();
 
-echo "dynamic getter access: " . (microtime(true) - $mark) . "\n";
+echo "dynamic getFoo(): " . (microtime(true) - $mark) . "\n";
 
 $mark = microtime(true);
 
 for($i=0;$i<1000;$i++)
   $object->foo;
 
-echo "raw attribute access: " . (microtime(true) - $mark) . "\n";
+echo "->foo: " . (microtime(true) - $mark) . "\n";



More information about the limb-svn mailing list