summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2016-02-25 16:26:39 -0800
committerJeremiah Senkpiel <fishrock123@rocketmail.com>2016-03-02 13:19:54 -0500
commit6aebe16669237509dce6a76f9e7991dd57d58f89 (patch)
tree51393c9ae1d7d8b7b1fca6a8a8f4a174dc23fad8 /benchmark
parentb44b701e5bcdd5a427915c887ab637b74b1400e9 (diff)
downloadnode-new-6aebe16669237509dce6a76f9e7991dd57d58f89.tar.gz
benchmark: add benchmark for buf.compare()
There is a benchmark for the class method `Buffer.compare()` but not for the instance method `buf.compare()`. This adds that benchmark. I used this to confirm a performance regression in an implementation I was considering. While the implementation was a bust, it does seem like the benchmark is worthwhile. The benchmark is nearly identical to the existing `Buffer.compare()` benchmark except, of course, that it calls `buf.compare()` instead. PR-URL: https://github.com/nodejs/node/pull/5441 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Evan Lucas <evanlucas@me.com>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/buffers/buffer-compare-instance-method.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/benchmark/buffers/buffer-compare-instance-method.js b/benchmark/buffers/buffer-compare-instance-method.js
new file mode 100644
index 0000000000..0becbeee23
--- /dev/null
+++ b/benchmark/buffers/buffer-compare-instance-method.js
@@ -0,0 +1,29 @@
+'use strict';
+const common = require('../common.js');
+const v8 = require('v8');
+
+const bench = common.createBenchmark(main, {
+ size: [16, 512, 1024, 4096, 16386],
+ millions: [1]
+});
+
+function main(conf) {
+ const iter = (conf.millions >>> 0) * 1e6;
+ const size = (conf.size >>> 0);
+ const b0 = new Buffer(size).fill('a');
+ const b1 = new Buffer(size).fill('a');
+
+ b1[size - 1] = 'b'.charCodeAt(0);
+
+ // Force optimization before starting the benchmark
+ b0.compare(b1);
+ v8.setFlagsFromString('--allow_natives_syntax');
+ eval('%OptimizeFunctionOnNextCall(b0.compare)');
+ b0.compare(b1);
+
+ bench.start();
+ for (var i = 0; i < iter; i++) {
+ b0.compare(b1);
+ }
+ bench.end(iter / 1e6);
+}