mirror of
https://github.com/nodejs/node.git
synced 2025-05-19 02:54:19 +00:00

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>
16 lines
436 B
JavaScript
16 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);
|
|
}
|