From 3288d7d2eae74c02bf7851b4efb1b8e65c9d28eb Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 23 Jan 2024 13:37:09 -0500 Subject: [PATCH] Add a benchmark for hexWrite --- package.json | 2 +- perf/write-hex.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 perf/write-hex.js diff --git a/package.json b/package.json index 536fe46c..5ee6b8d9 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ }, "scripts": { "perf": "browserify --debug perf/bracket-notation.js > perf/bundle.js && open perf/index.html", - "perf-node": "node perf/bracket-notation.js && node perf/concat.js && node perf/copy-big.js && node perf/copy.js && node perf/new-big.js && node perf/new.js && node perf/readDoubleBE.js && node perf/readFloatBE.js && node perf/readUInt32LE.js && node perf/slice.js && node perf/writeFloatBE.js", + "perf-node": "node perf/bracket-notation.js && node perf/concat.js && node perf/copy-big.js && node perf/copy.js && node perf/new-big.js && node perf/new.js && node perf/readDoubleBE.js && node perf/readFloatBE.js && node perf/readUInt32LE.js && node perf/slice.js && node perf/writeFloatBE.js && node perf/write-hex.js", "size": "browserify -r ./ | uglifyjs -c -m | gzip | wc -c", "standard": "standard", "test": "tape test/*.js test/node/*.js", diff --git a/perf/write-hex.js b/perf/write-hex.js new file mode 100644 index 00000000..76b03be5 --- /dev/null +++ b/perf/write-hex.js @@ -0,0 +1,24 @@ +const BrowserBuffer = require('../').Buffer // (this module) +const util = require('./util') +const suite = util.suite() + +const LENGTH = 4096 +const browserSubject = BrowserBuffer.alloc(LENGTH) +const nodeSubject = Buffer.alloc(LENGTH) + +const charset = '0123456789abcdef' + +let str = '' + +for (let i = 0; i < LENGTH * 2; i++) + str += charset[Math.random() * charset.length | 0] + +suite + .add('BrowserBuffer#write(' + LENGTH + ', "hex")', function () { + browserSubject.write(str, 'hex') + }) + +if (!process.browser) suite + .add('NodeBuffer#write(' + LENGTH + ', "hex")', function () { + nodeSubject.write(str, 'hex') + })