beatgammit/base64-js — pull request #4 by dominictarr (2013-12-30 04:59:30+00:00)
Title: make decoding base64 10x faster

this pull request makes decoding base64 much much faster.
the trick was to use a hard coded offsets and comparisons and toCharCode
to compute the value for a character, instead of searching for that character in a table.

results, on a 100k random value,
note (on `{de,en}code ms` columns, lower is better, but on `ops/ms` colums, higher is better.
```
[dominic@COMPUTER base64-js]$ git checkout f617396dabd1dab18a069de7a48acbdc95498c09
HEAD is now at f617396... simple script to measure time to decode/encode
[dominic@COMPUTER base64-js]$ node test/bench.js
decode ms, decode ops/ms, encode ms, encode ops/ms
494 2699.0607287449393 91 14652.043956043955
[dominic@COMPUTER base64-js]$ git checkout 96c7a98bfb5c4ac10f30d60920e2ce8fc7c24b41
HEAD is now at 96c7a98... base64-js uses tabs, sorry!
[dominic@COMPUTER base64-js]$ node test/bench.js
decode ms, decode ops/ms, encode ms, encode ops/ms
41 32520.39024390244 80 16666.7
```

There also seems to be a 10% improvement in encode perf, not sure what that is from.

Okay, so the one thing, is that this switches to `Uint8Array`, so we need to discuss the best way to
both support old browsers and to enable the perf improvement that TypedArrays allow.
Maybe the answer is just to use @substack's typedarray polyfil?
Also there is @feross's https://github.com/feross/native-buffer-browserify
but i'd like to compare that against raw typedarrays for a real world use case
(I have one here: github.com/dominictarr/sha.js before commiting to anything)