TextDecoder - many small calls (v2)

Revision 2 of this benchmark created on


Setup

const utf8Decoder = new TextDecoder();
const data = new Uint8Array(100_000);

for (var i = 0; i < data.length;) {
  // Initialize to a repeated sequence of
  // "xx€" to test both 1-byte and 3-byte
  // utf8 decoding performance.
  data[i++] = 120;  // 'x'
  data[i++] = 120;  // 'x'
  data[i++] = 226;  // '€' byte 1
  data[i++] = 130;  // '€' byte 2
  data[i++] = 172;  // '€' byte 3
}

Test runner

Ready to run.

Testing in
TestOps/sec
Many small calls
var results = [];
var ofs = 0;
for (var i = 0; i < 10_000; i++, ofs += 10) {
  results.push(utf8Decoder.decode(data.subarray(ofs, ofs + 10)));
}
if (results.length != 10_000) throw "bad";			
ready
Changed bindings
var results = [];
var ofs = 0;
for (var i = 0; i < 10_000; i++, ofs += 10) {
  results.push(utf8Decoder.decodeFast(data.subarray(ofs, ofs + 10)));
}
if (results.length != 10_000) throw "bad";			
ready

Revisions

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