summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2015-07-15 22:09:52 +0200
committerBen Noordhuis <info@bnoordhuis.nl>2015-07-25 19:07:23 +0200
commit8fd3ce100eb30324f01da8f4e8d501a0369c6a44 (patch)
tree95c578c5176d70432e2f22eea73fe0c2975259fd /benchmark
parentb148c0dff3c41d59886352eb5dfd4d217db0a02d (diff)
downloadandroid-node-v8-8fd3ce100eb30324f01da8f4e8d501a0369c6a44.tar.gz
android-node-v8-8fd3ce100eb30324f01da8f4e8d501a0369c6a44.tar.bz2
android-node-v8-8fd3ce100eb30324f01da8f4e8d501a0369c6a44.zip
src: make base64 decoding 50% faster
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>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/buffers/buffer-base64-decode.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/benchmark/buffers/buffer-base64-decode.js b/benchmark/buffers/buffer-base64-decode.js
new file mode 100644
index 0000000000..76850c1231
--- /dev/null
+++ b/benchmark/buffers/buffer-base64-decode.js
@@ -0,0 +1,15 @@
+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);
+}