Make the inner loop execute fewer compare-and-branch executions per
processed byte, resulting in a 50% or more speedup.
This coincidentally fixes an out-of-bounds read:
while (unbase64(*src) < 0 && src < srcEnd)
Should have read:
while (src < srcEnd && unbase64(*src) < 0)
But this commit removes the offending code altogether.
Fixes: https://github.com/nodejs/io.js/issues/2166
PR-URL: https://github.com/nodejs/io.js/pull/2193
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
15 lines
436 B
JavaScript
15 lines
436 B
JavaScript
var assert = require('assert');
|
|
var common = require('../common.js');
|
|
|
|
var bench = common.createBenchmark(main, {});
|
|
|
|
function main(conf) {
|
|
for (var s = 'abcd'; s.length < 32 << 20; s += s);
|
|
s.match(/./); // Flatten string.
|
|
assert.equal(s.length % 4, 0);
|
|
var b = Buffer(s.length / 4 * 3);
|
|
b.write(s, 0, s.length, 'base64');
|
|
bench.start();
|
|
for (var i = 0; i < 32; i += 1) b.base64Write(s, 0, s.length);
|
|
bench.end(32);
|
|
}
|