Skip to content

Instantly share code, notes, and snippets.

@chrisdickinson
Created April 2, 2015 03:03
Show Gist options
  • Save chrisdickinson/5fbcbd3843078bc31bdc to your computer and use it in GitHub Desktop.
Save chrisdickinson/5fbcbd3843078bc31bdc to your computer and use it in GitHub Desktop.
'use strict'
const common = require('../common.js');
const bench = common.createBenchmark(main, {
range: [0x7F, 0x7FF, 0x7FFF],
size: [1<<14, 1<<16, 1<<20]
});
function main(conf) {
let arr = new Array(Number(conf.size))
fillBuffer(Number(conf.range), arr)
measure(new Buffer(arr))
}
function measure(buf) {
bench.start()
let size = buf.stripInvalidUtf8() // added this – runs Utf8Value::StripInvalidUtf8 on the buffer data
bench.end(1, buf.slice(0, size).length)
}
function fillBuffer(range, out) {
for (let i = 0; i < out.length; ++i) {
out[i] = String.fromCodePoint(i % range)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment