[limb-svn] r6529 - in 3.x/trunk/limb/macro: src tests/bench
svn at limb-project.com
svn at limb-project.com
Mon Nov 19 22:31:46 MSK 2007
Author: pachanga
Date: 2007-11-19 22:31:46 +0300 (Mon, 19 Nov 2007)
New Revision: 6529
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6529
Added:
3.x/trunk/limb/macro/tests/bench/profile.inc.php
Removed:
3.x/trunk/limb/macro/tests/bench/end.inc.php
3.x/trunk/limb/macro/tests/bench/macro-force.php
3.x/trunk/limb/macro/tests/bench/start.inc.php
Modified:
3.x/trunk/limb/macro/src/lmbMacroFilterDictionary.class.php
3.x/trunk/limb/macro/src/lmbMacroTagDictionary.class.php
3.x/trunk/limb/macro/tests/bench/macro.php
3.x/trunk/limb/macro/tests/bench/native.php
3.x/trunk/limb/macro/tests/bench/wact.php
Log:
-- caching of filters and tags dictionaries added(forcescan = false)
-- some refactoring of bench tests
Modified: 3.x/trunk/limb/macro/src/lmbMacroFilterDictionary.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroFilterDictionary.class.php 2007-11-19 18:21:05 UTC (rev 6528)
+++ 3.x/trunk/limb/macro/src/lmbMacroFilterDictionary.class.php 2007-11-19 19:31:46 UTC (rev 6529)
@@ -19,7 +19,6 @@
class lmbMacroFilterDictionary
{
protected $info = array();
- protected $output_filter_info;
static protected $instance;
static function instance()
@@ -33,14 +32,40 @@
function load(lmbMacroConfig $config)
{
+ if(!$config->isForceScan() && $this->_loadCache($config))
+ return;
+
$dirs = $config->getFiltersScanDirectories();
foreach($dirs as $dir)
{
foreach(lmb_glob($dir . '/*.filter.php') as $file)
$this->registerFromFile($file);
}
+
+ $this->_saveCache($config);
}
+ protected function _loadCache(lmbMacroConfig $config)
+ {
+ $cache_file = $config->getCacheDir() . '/filters.cache';
+ if(!file_exists($cache_file))
+ return false;
+
+ $info = @unserialize(file_get_contents($cache_file));
+ if($info === false || !is_array($info))
+ return false;
+
+ $this->info = $info;
+
+ return true;
+ }
+
+ protected function _saveCache(lmbMacroConfig $config)
+ {
+ $cache_file = $config->getCacheDir() . '/filters.cache';
+ lmbFs :: safeWrite($cache_file, serialize($this->info));
+ }
+
function register($filter_info)
{
$names = array(strtolower($filter_info->getName()));
@@ -49,7 +74,6 @@
if(count($aliases))
{
$aliases = array_map('strtolower', $aliases);
-
$names = array_merge($names, $aliases);
}
Modified: 3.x/trunk/limb/macro/src/lmbMacroTagDictionary.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroTagDictionary.class.php 2007-11-19 18:21:05 UTC (rev 6528)
+++ 3.x/trunk/limb/macro/src/lmbMacroTagDictionary.class.php 2007-11-19 19:31:46 UTC (rev 6529)
@@ -19,7 +19,6 @@
class lmbMacroTagDictionary
{
protected $info = array();
- protected $output_tag_info;
static protected $instance;
static function instance()
@@ -33,6 +32,9 @@
function load(lmbMacroConfig $config)
{
+ if(!$config->isForceScan() && $this->_loadCache($config))
+ return;
+
$config_scan_dirs = $config->getTagsScanDirectories();
$real_scan_dirs = array();
@@ -47,6 +49,8 @@
foreach(lmb_glob($scan_dir . '/*.tag.php') as $file)
$this->registerFromFile($file);
}
+
+ $this->_saveCache($config);
}
function _getThisAndImmediateDirectories($dir)
@@ -62,6 +66,27 @@
return $dirs;
}
+ protected function _loadCache(lmbMacroConfig $config)
+ {
+ $cache_file = $config->getCacheDir() . '/tags.cache';
+ if(!file_exists($cache_file))
+ return false;
+
+ $info = @unserialize(file_get_contents($cache_file));
+ if($info === false || !is_array($info))
+ return false;
+
+ $this->info = $info;
+
+ return true;
+ }
+
+ protected function _saveCache(lmbMacroConfig $config)
+ {
+ $cache_file = $config->getCacheDir() . '/tags.cache';
+ lmbFs :: safeWrite($cache_file, serialize($this->info));
+ }
+
function register($tag_info)
{
$names = array(strtolower($tag_info->getTag()));
@@ -70,7 +95,6 @@
if(count($aliases))
{
$aliases = array_map('strtolower', $aliases);
-
$names = array_merge($names, $aliases);
}
Deleted: 3.x/trunk/limb/macro/tests/bench/end.inc.php
===================================================================
--- 3.x/trunk/limb/macro/tests/bench/end.inc.php 2007-11-19 18:21:05 UTC (rev 6528)
+++ 3.x/trunk/limb/macro/tests/bench/end.inc.php 2007-11-19 19:31:46 UTC (rev 6529)
@@ -1,25 +0,0 @@
-<?php
-
-$time = microtime(true) - $start;
-
-echo "\ntime: $time sec.\n";
-
-$class_stat = false;
-foreach($argv as $arg)
-{
- if($arg == '--classes')
- $class_stat = true;
-}
-
-if($class_stat)
-{
- $classes = array();
- foreach(get_declared_classes() as $class)
- {
- $refl = new ReflectionClass($class);
- if(strpos($refl->getFileName(), 'src/') !== false)
- $classes[] = $class;
- }
- sort($classes);
- var_dump($classes);
-}
Deleted: 3.x/trunk/limb/macro/tests/bench/macro-force.php
===================================================================
--- 3.x/trunk/limb/macro/tests/bench/macro-force.php 2007-11-19 18:21:05 UTC (rev 6528)
+++ 3.x/trunk/limb/macro/tests/bench/macro-force.php 2007-11-19 19:31:46 UTC (rev 6529)
@@ -1,17 +0,0 @@
-<?php
-
-set_include_path(dirname(__FILE__) . '/../../../../');
-require_once('limb/core/common.inc.php');
-require_once('limb/macro/src/lmbMacroTemplate.class.php');
-
-include('start.inc.php');
-
-$config = new lmbMacroConfig('/tmp/macro', true, true, array(dirname(__FILE__) . '/tpl'));
-
-for($i=0;$i<1000;$i++)
-{
- $tpl = new lmbMacroTemplate('macro.phtml', $config);
- $tpl->render();
-}
-
-include('end.inc.php');
Modified: 3.x/trunk/limb/macro/tests/bench/macro.php
===================================================================
--- 3.x/trunk/limb/macro/tests/bench/macro.php 2007-11-19 18:21:05 UTC (rev 6528)
+++ 3.x/trunk/limb/macro/tests/bench/macro.php 2007-11-19 19:31:46 UTC (rev 6529)
@@ -4,23 +4,35 @@
die("\nTemplate argument is required\n");
$file = $argv[1];
+$forcecompile = false;
+if(isset($argv[2]))
+ $forcecompile = (bool)$argv[2];
+
+$forcescan = false;
+if(isset($argv[3]))
+ $forcescan = (bool)$argv[3];
+
set_include_path(dirname(__FILE__) . '/../../../../');
require_once('limb/core/common.inc.php');
require_once('limb/macro/src/lmbMacroTemplate.class.php');
+require_once(dirname(__FILE__) . '/profile.inc.php');
-$tpl = new lmbMacroTemplate($file, new lmbMacroConfig('/tmp/macro', false, false, array(dirname(__FILE__) . '/tpl')));
+$tpl = new lmbMacroTemplate($file, new lmbMacroConfig('/tmp/macro', $forcecompile, $forcescan, array(dirname(__FILE__))));
for($i=2;$i<$argc;$i++)
{
+ if(strpos($argv[$i], '=') === false)
+ continue;
+
list($key, $value) = explode('=', $argv[$i]);
$tpl->set($key, $value);
}
-include('start.inc.php');
+profile_start();
for($i=0;$i<1000;$i++)
{
$tpl->render();
}
-include('end.inc.php');
+profile_end("running $i iterations of render");
Modified: 3.x/trunk/limb/macro/tests/bench/native.php
===================================================================
--- 3.x/trunk/limb/macro/tests/bench/native.php 2007-11-19 18:21:05 UTC (rev 6528)
+++ 3.x/trunk/limb/macro/tests/bench/native.php 2007-11-19 19:31:46 UTC (rev 6529)
@@ -1,9 +1,11 @@
<?php
-include('start.inc.php');
+require_once(dirname(__FILE__) . '/profile.inc.php');
$name = 'Bob';
+profile_start();
+
for($i=0;$i<1000;$i++)
{
ob_start();
@@ -12,5 +14,4 @@
ob_end_clean();
}
-include('end.inc.php');
-
+profile_end("running $i iterations of include");
Added: 3.x/trunk/limb/macro/tests/bench/profile.inc.php
===================================================================
--- 3.x/trunk/limb/macro/tests/bench/profile.inc.php (rev 0)
+++ 3.x/trunk/limb/macro/tests/bench/profile.inc.php 2007-11-19 19:31:46 UTC (rev 6529)
@@ -0,0 +1,28 @@
+<?php
+
+function profile_start()
+{
+ global $profile_start;
+ $profile_start = microtime(true);
+}
+
+function profile_end($label = "time", $class_stat = false)
+{
+ global $profile_start;
+ $time = microtime(true) - $profile_start;
+
+ echo "$label: $time sec.\n";
+
+ if($class_stat)
+ {
+ $classes = array();
+ foreach(get_declared_classes() as $class)
+ {
+ $refl = new ReflectionClass($class);
+ if(strpos($refl->getFileName(), 'src/') !== false)
+ $classes[] = $class;
+ }
+ sort($classes);
+ var_dump($classes);
+ }
+}
Deleted: 3.x/trunk/limb/macro/tests/bench/start.inc.php
===================================================================
--- 3.x/trunk/limb/macro/tests/bench/start.inc.php 2007-11-19 18:21:05 UTC (rev 6528)
+++ 3.x/trunk/limb/macro/tests/bench/start.inc.php 2007-11-19 19:31:46 UTC (rev 6529)
@@ -1,3 +0,0 @@
-<?php
-
-$start = microtime(true);
Modified: 3.x/trunk/limb/macro/tests/bench/wact.php
===================================================================
--- 3.x/trunk/limb/macro/tests/bench/wact.php 2007-11-19 18:21:05 UTC (rev 6528)
+++ 3.x/trunk/limb/macro/tests/bench/wact.php 2007-11-19 19:31:46 UTC (rev 6529)
@@ -6,10 +6,11 @@
set_include_path(dirname(__FILE__) . '/../../../../');
define('WACT_CACHE_DIR', '/tmp/wact');
-define('WACT_TPLS', dirname(__FILE__) . '/tpl');
+define('WACT_TPLS', dirname(__FILE__));
require_once('limb/wact/common.inc.php');
require_once('limb/wact/src/WactTemplate.class.php');
require_once('limb/wact/src/WactDefaultTemplateConfig.class.php');
+require_once(dirname(__FILE__) . '/profile.inc.php');
$tpl = new WactTemplate($file, new WactDefaultTemplateConfig(dirname(__FILE__) . '/settings/wact.ini'));
@@ -19,11 +20,11 @@
$tpl->set($key, $value);
}
-include('start.inc.php');
+profile_start();
for($i=0;$i<1000;$i++)
{
$tpl->capture();
}
-include('end.inc.php');
+profile_end("running $i iterations of capture");
More information about the limb-svn
mailing list