TextDecoder (v4)

Revision 4 of this benchmark created on


Setup

const utf8Decoder = new TextDecoder();
const data = new Uint8Array(100_000);
const code = "x".charCodeAt(0);

// Initialize the array to a valid ASCII value
// to ensure that NULL isn't doing anything
// weird here.
for (var i = 0; i < data.length; i++) {
  data[i] = code;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Many small calls
var ofs = 0;
for (var i = 0; i < 10_000; i++, ofs += 10) {
  utf8Decoder.decode(data.subarray(ofs, ofs + 10));
}
ready
One big call
const str = utf8Decoder.decode(data);
var ofs = 0;
for (var i = 0; i < 10_000; i++, ofs += 10) {
  str.substring(ofs, ofs + 10);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.