Skip to content

Commit

Permalink
Add a benchmark for hexWrite
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Jan 23, 2024
1 parent d513509 commit 3288d7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 24 additions & 0 deletions perf/write-hex.js
Original file line number Diff line number Diff line change
@@ -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')
})

0 comments on commit 3288d7d

Please sign in to comment.