public static function flush() { self::$_instances = array(); }
public function testScalability() { $route = $this->_createInstance(); $Post = ClassRegistry::init('Post'); $Author = ClassRegistry::init('Author'); $Post->deleteAll(true); $Author->deleteAll(true); $recordUnit = 1000; $unitAmount = 100; $recordsCount = $recordUnit * $unitAmount; var_dump("testing {$recordsCount} records:"); $start = microtime(true); for ($i = 0; $i < $unitAmount; $i++) { $save = array(); for ($j = 1; $j <= $recordUnit; $j++) { $n = $i * $recordUnit + $j; $save['Author'][$n] = "({$n}, 'user{$n}', 'password{$n}', '2011-11-11 11:11:11', '2011-11-11 11:11:11')"; $save['Post'][$n] = "({$n}, 'Post{$n}', 'body{$n}', 'Y', {$n}, '2011-11-11 11:11:11', '2011-11-11 11:11:11')"; } $Author->getDataSource()->insertMulti('authors', array('id', 'user', 'password', 'created', 'updated'), $save['Author']); $Post->getDataSource()->insertMulti('posts', array('id', 'title', 'body', 'published', 'author_id', 'created', 'updated'), $save['Post']); } $end = microtime(true) - $start; var_dump(sprintf('inserting records took %.1f msec', 1000.0 * $end)); $start = microtime(true); $result = $route->parse('/post/user100/Post100'); $end = microtime(true) - $start; var_dump(sprintf('non cached parsing took %.1f msec', 1000.0 * $end)); $this->assertEqual($result['controller'], 'posts'); $this->assertEqual($result['action'], 'view'); $this->assertEqual($result['pass'], array(100)); $start = microtime(true); $result = $route->parse('/post/user100/Post100'); $end = microtime(true) - $start; var_dump(sprintf('after 1 cached parsing took %.1f msec', 1000.0 * $end)); MultiSlugRoute::clearCacheAll(); /* $start = microtime(true); for ($i = 1; $i <= $recordsCount; $i++) { $startIndivisual = microtime(true); $route->parse("/post/user$i/Post$i"); if ($i === 2 || $i === $n) { var_dump(sprintf($i . ': %.1f msec', 1000.0 * (microtime(true) - $startIndivisual))); } } $end = microtime(true) - $start; var_dump(sprintf('%.1f msec', 1000.0 * $end)); var_dump(sprintf('average %.1f msec', 1000.0 * $end / (float)$n)); */ $start = microtime(true); for ($i = 1; $i <= $recordsCount; $i++) { $route->map("/post/user{$i}/Post{$i}", array('controller' => 'posts', 'action' => 'view', 'pass' => array($i), 'named' => array())); } $end = microtime(true) - $start; var_dump(sprintf('mapping took %.1f msec', 1000.0 * $end)); $route = $this->_createInstance(); $start = microtime(true); $result = $route->parse('/post/user100/Post100'); $end = microtime(true) - $start; var_dump(sprintf('after all cached parsing with loading cache took %.1f msec', 1000.0 * $end)); var_dump(sprintf('loading cache took %.1f msec', 1000.0 * $route->elapsed)); $start = microtime(true); $result = $route->parse('/post/user100/Post100'); $end = microtime(true) - $start; var_dump(sprintf('after all cached parsing took %.1f msec', 1000.0 * $end)); }