laravel/framework — pull request #2952 by dyatlov (2013-12-14 00:32:41+00:00)
Title: Improved Blade Compiler speed in 13.5 times. Called the new compiler - B...

...lade2. Didnt want to replace old Blade as it requires good thorough testing and output is not exaclty the same (difference in line endings).

Speed was tested this way:

```

public function testCompileSpeed()
{
$data = file_get_contents('/path/to/file/template.blade.php');

$compiler = new Blade2Compiler($this->getFiles(), __DIR__);

$start = microtime(true);
for($i = 0; $i < 1000; $i++) {
$compiler->compileString($data);
}
$time = microtime(true) - $start;

$this->assertEquals('', $time); //bad way - but coded it in 2 secs so acceptable for temporary testing
}

```

And then I inserted the same function into BladeCompilerTest (and changed Blade2Compiler to BladeCompiler).
Blade2Compiler has shown `1.99 seconds`; BladeCompiler - `27.07 seconds`. So I improved compile speed in 13.5 about times :)

This is due to reduced usage of regular expressions.

Also, This new Blade2 compiler passes 2 new tests which old Blade2 was unable to:

```
public function testCustomPhpCodeIsCorrectlyHandled()
{
$compiler = new Blade2Compiler($this->getFiles(), __DIR__);
$this->assertEquals(' ', $compiler->compileString("@if(\$test) @endif"));
}

public function testMixingYieldAndEcho()
{
$compiler = new Blade2Compiler($this->getFiles(), __DIR__);
$this->assertEquals('yieldContent(\'title\'); ?> - ', $compiler->compileString("@yield('title') - {{Config::get('site.title')}}"));
}
```

Compilers are fully compatible and Blade2 passes all phpunit tests of Blade. But there is small issue - on a real template they produce not exactly same output - difference is in line endings (LF\CR). Old blade uses '\r\n' but Blade2 uses native file endings (except thing with `@extends` where for compatibility I added \r\n to pass phpunit test).

You're welcome to test speed and compatibility yourself :)