Saturday 12 August 2017

Faster zeroing of typed arrays?

Zeroing typed arrays in Node.js is painfully slow. On my machine with 1Mb array it is about 0.45 op/ms:let a = new Uint8Array(1000000); start = process.hrtime(); const runs = 1000; for (let i = 0; i < runs; i++) { a.fill(0); } let ms = to_ms(process.hrtime(start)); console.log(ms, "ms,", runs / ms, "op/ms"); function to_ms(hr) { return (hr[0] * 1e9 + hr[1]) / 1e6; } Is there a better way to clear typed arrays, short of creating a new array (so as to not produce excessive garbage)?

Submitted August 12, 2017 at 01:16PM by jshacker

No comments:

Post a Comment