gradus/coffeecup — pull request #21 by wmertens (2012-04-02 08:51:13+00:00)
Title: Some speedups

With these changes, you can use -z for the coffeecup executable to get an optimized version, and there's a 10-15% speed increase for the optimized version and 5% for the regular:

Original:

```bash
$ ./optimized_bench.coffee
coffeecup (precompiled): 7887 ms
coffeecup (precompiled, optimized): 333 ms
```

Now:

```bash
$ ./optimized_bench.coffee
coffeecup (precompiled): 7442 ms
coffeecup (precompiled, optimized): 291 ms
```

The optimized version now outputs things like

```javascript
if (this.inspired) {
text("

Create a witty example

");
} else {
text("

Go meta

");
}

text('');
```

instead of

```javascript
if (this.inspired) {
text("

");
text("Create a witty example");
text("

");
} else {
text("

");
text("Go meta");
text("

");
}

text('');
```

Note that it splits up the string concatenation; it's faster to run ```text()``` twice than to create a concatenated string which gets concatenated.

There is more room for optimization; the text() calls could be inlined into the array push for example (speed), and there could be a mangling run after optimization (size).

All tests pass. This was fun to write, I learned a lot about JS optimization, especially that what seems faster often isn't :-) (jsperf.com FTW!)