xp-forge/handlebars — pull request #1 by thekid (2014-01-03 19:09:29+00:00)
Title: Helpers as nodes

This pull request changes the block helpers from builtin helpers over to specialized `BlockHelper` nodes, and boosts performance enormously:

```php
array('name' => 'World'));
$template= 'Hello, {{#if person}}{{#with person}}{{name}}{{/with}}{{/if}}';
$times= 100000;

// Code
$engine= new HandlebarsEngine();
$compiled= $engine->compile($template);
$context= create(new DataContext($data))->withEngine($engine);
$t= Timer::measure(function() use($times, $engine, $compiled, $context) {
for ($i= 0; $i < $times; $i++) {
$compiled->evaluate($context);
}
});
$this->out->writeLine($engine->evaluate($compiled, $context));
$this->out->writeLinef('%d times, %.3f seconds', $times, $t->elapsedTime());
}
}
```

### master
```sh
$ xpcli Benchmark.class.php
Hello, World
100000 times, 9.802 seconds
```

### helpers-as-nodes
```sh
$ xpcli Benchmark.class.php
Hello, World
100000 times, 2.090 seconds
```