creationix/jsonparse — pull request #9 by lbdremy (2012-10-06 01:41:00+00:00)
Title: Performance improvement

Hello @creationix,

I played recently with the profiling capabilities of v8 with the options --prof, --trace-opt and --trace-bailout and I noticed that v8 does not optimized functions with switch statement.
So I removed all switch statement from all hot functions `proto.onToken` and `proto.write` in `jsonparse`, the result is pretty nice, it cuts by almost two the time spent to parse.
I wrote more details in this git with all logs from all commands I run. https://gist.github.com/3843382

But basically running `bench.js`, before I got:

```sh
JSON.parse took 97
streaming parser took 416
streaming is 4.288659793814433 times slower
JSON.parse took 97
streaming parser took 413
streaming is 4.257731958762887 times slower
JSON.parse took 96
streaming parser took 414
streaming is 4.3125 times slower
JSON.parse took 95
streaming parser took 413
streaming is 4.347368421052631 times slower
JSON.parse took 95
streaming parser took 418
streaming is 4.4 times slower
JSON.parse took 99
streaming parser took 413
streaming is 4.171717171717172 times slower
JSON.parse took 96
streaming parser took 420
streaming is 4.375 times slower
```

now I get:

```sh
streaming parser took 229
streaming is 2.3608247422680413 times slower
JSON.parse took 95
streaming parser took 225
streaming is 2.3684210526315788 times slower
JSON.parse took 96
streaming parser took 239
streaming is 2.4895833333333335 times slower
JSON.parse took 95
streaming parser took 224
streaming is 2.357894736842105 times slower
JSON.parse took 96
streaming parser took 225
streaming is 2.34375 times slower
JSON.parse took 96
streaming parser took 226
streaming is 2.3541666666666665 times slower
JSON.parse took 96
streaming parser took 223
streaming is 2.3229166666666665 times slower
JSON.parse took 97
streaming parser took 227
streaming is 2.3402061855670104 times slower
```

Cool, is it?