diff options
author | Brian White <mscdex@mscdex.net> | 2019-08-09 07:29:48 -0400 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-08-14 15:59:32 -0700 |
commit | 6d351d4cc0a6feb644e7f81051d319b53bbc9309 (patch) | |
tree | 8c8f57272b4d69517d759472d5b19441d6ccf490 /benchmark | |
parent | e505a741e30d7101a0c4b9159d9e48589a76e16c (diff) | |
download | android-node-v8-6d351d4cc0a6feb644e7f81051d319b53bbc9309.tar.gz android-node-v8-6d351d4cc0a6feb644e7f81051d319b53bbc9309.tar.bz2 android-node-v8-6d351d4cc0a6feb644e7f81051d319b53bbc9309.zip |
buffer: improve copy() performance
PR-URL: https://github.com/nodejs/node/pull/29066
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/buffers/buffer-copy.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/benchmark/buffers/buffer-copy.js b/benchmark/buffers/buffer-copy.js new file mode 100644 index 0000000000..164f314207 --- /dev/null +++ b/benchmark/buffers/buffer-copy.js @@ -0,0 +1,19 @@ +'use strict'; +const common = require('../common.js'); + +const bench = common.createBenchmark(main, { + bytes: [0, 8, 128, 32 * 1024], + partial: ['true', 'false'], + n: [6e6] +}); + +function main({ n, bytes, partial }) { + const source = Buffer.allocUnsafe(bytes); + const target = Buffer.allocUnsafe(bytes); + const sourceStart = (partial === 'true' ? Math.floor(bytes / 2) : 0); + bench.start(); + for (let i = 0; i < n; i++) { + source.copy(target, 0, sourceStart); + } + bench.end(n); +} |