From 24142b4a5a6595d43bbf894cc0091e8587ca9bd8 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 22 May 2014 20:37:47 -0700 Subject: [PATCH] benchmark: Add a test to measure Buffer.slice method See https://github.com/joyent/node/issues/7633 --- benchmark/buffers/buffer-slice.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 benchmark/buffers/buffer-slice.js diff --git a/benchmark/buffers/buffer-slice.js b/benchmark/buffers/buffer-slice.js new file mode 100644 index 000000000000..f632fa64adff --- /dev/null +++ b/benchmark/buffers/buffer-slice.js @@ -0,0 +1,20 @@ +var common = require('../common.js'); +var SlowBuffer = require('buffer').SlowBuffer; + +var bench = common.createBenchmark(main, { + type: ['fast', 'slow'], + n: [1024] +}); + +var buf = new Buffer(1024); +var slowBuf = new SlowBuffer(1024); + +function main(conf) { + var n = +conf.n; + var b = conf.type === 'fast' ? buf : slowBuf; + bench.start(); + for (var i = 0; i < n * 1024; i++) { + b.slice(10, 256); + } + bench.end(n); +}