summaryrefslogtreecommitdiff
path: root/benchmark/buffers/buffer-equals.js
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark/buffers/buffer-equals.js')
-rw-r--r--benchmark/buffers/buffer-equals.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/benchmark/buffers/buffer-equals.js b/benchmark/buffers/buffer-equals.js
new file mode 100644
index 0000000000..99d2472bd3
--- /dev/null
+++ b/benchmark/buffers/buffer-equals.js
@@ -0,0 +1,22 @@
+'use strict';
+const common = require('../common.js');
+
+const bench = common.createBenchmark(main, {
+ size: [0, 512, 16386],
+ difflen: ['true', 'false'],
+ n: [1e6]
+});
+
+function main({ n, size, difflen }) {
+ const b0 = Buffer.alloc(size, 'a');
+ const b1 = Buffer.alloc(size + (difflen === 'true' ? 1 : 0), 'a');
+
+ if (b1.length > 0)
+ b1[b1.length - 1] = 'b'.charCodeAt(0);
+
+ bench.start();
+ for (let i = 0; i < n; i++) {
+ b0.equals(b1);
+ }
+ bench.end(n);
+}