Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup

  • Loading branch information...
commit 45d515624493e0e2a6f451f83573e95a0229f645 1 parent 128aa92
@jbboehr authored
Showing with 24 additions and 7 deletions.
  1. +21 −4 bench.php
  2. +3 −3 mustache_mustache.cpp
View
25 bench.php
@@ -1,24 +1,31 @@
<?php
$count = 100000;
+$startMemory = memory_get_usage(true);
$tmplStr = '{{test}}';
$dataArr = array(
'test' => 'val',
);
-printf('%10s %10s %10s %10s' . PHP_EOL, 'Type', 'Total (s)', 'Each (s)', 'Count');
+printf('%10s %10s %10s %10s %10s' . PHP_EOL, 'Type', 'Total (s)', 'Each (s)', 'Count', 'Memory Delta (B)');
// Normal
+$name = 'Normal';
+$startMemory = memory_get_usage(true);
$start = microtime(true);
$mustache = new Mustache();
for( $i = 0; $i < $count; $i++ ) {
$out = $mustache->render($tmplStr, $dataArr);
}
$stop = microtime(true);
-printf('%10s %10f %10f %10d' . PHP_EOL, 'Normal', ($stop - $start), (($stop - $start) / $count), $count);
+$stopMemory = memory_get_usage(true);
+printf('%10s %10f %10f %10d %10s' . PHP_EOL,
+ $name, ($stop - $start), (($stop - $start) / $count), $count, number_format($stopMemory - $startMemory));
// Compiled
+$name = 'Compiled';
+$startMemory = memory_get_usage(true);
$start = microtime(true);
$mustache = new Mustache();
$ret = $mustache->compile($tmplStr);
@@ -26,9 +33,13 @@
$out = $ret->render($dataArr);
}
$stop = microtime(true);
-printf('%10s %10f %10f %10d' . PHP_EOL, 'Compiled', ($stop - $start), (($stop - $start) / $count), $count);
+$stopMemory = memory_get_usage(true);
+printf('%10s %10f %10f %10d %10s' . PHP_EOL,
+ $name, ($stop - $start), (($stop - $start) / $count), $count, number_format($stopMemory - $startMemory));
// Compiled+Data
+$name = 'Compiled2';
+$startMemory = memory_get_usage(true);
$start = microtime(true);
$tmpl = new MustacheTemplate($tmplStr);
$data = new MustacheData($dataArr);
@@ -36,5 +47,11 @@
$out = $tmpl->render($data);
}
$stop = microtime(true);
-printf('%10s %10f %10f %10d' . PHP_EOL, 'Compiled2', ($stop - $start), (($stop - $start) / $count), $count);
+$stopMemory = memory_get_usage(true);
+printf('%10s %10f %10f %10d %10s' . PHP_EOL,
+ $name, ($stop - $start), (($stop - $start) / $count), $count, number_format($stopMemory - $startMemory));
+echo PHP_EOL;
+printf("Memory (start): %s" . PHP_EOL, number_format($startMemory));
+printf("Memory (end): %s" . PHP_EOL, number_format(memory_get_usage(true)));
+printf("Memory (peak): %s" . PHP_EOL, number_format(memory_get_peak_usage(true)));
View
6 mustache_mustache.cpp
@@ -307,7 +307,7 @@ PHP_METHOD(Mustache, compile)
long template_len;
std::string templateStr;
mustache::Node * root;
- std::string className("MustacheTemplate");
+ std::string className;
zend_class_entry * MustacheTemplate_ce_ptr;
php_obj_MustacheTemplate * intern;
@@ -323,10 +323,10 @@ PHP_METHOD(Mustache, compile)
// Main
try {
- // Assign template to string
templateStr.assign(template_str, (size_t) template_len);
// Get MustacheTemplate class entry
+ className.assign("MustacheTemplate");
MustacheTemplate_ce_ptr = mustache_get_class_entry((char *)className.c_str(), className.length() TSRMLS_CC);
if( MustacheTemplate_ce_ptr == NULL ) {
@@ -336,7 +336,7 @@ PHP_METHOD(Mustache, compile)
}
// Initialize new object
- object_init_ex(return_value, MustacheTemplate_ce_ptr);
+ object_init_ex(return_value, MustacheTemplate_ce_ptr TSRMLS_CC);
intern = (php_obj_MustacheTemplate *) zend_objects_get_address(return_value TSRMLS_CC);
// Get object's internal node pointer
Please sign in to comment.
Something went wrong with that request. Please try again.