jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Explain if worth getting str.length to variable at start of function when converting a String to ArrayBuffer.
function str2ab(str) {
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0; i<str.length; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
function str2abWithVariable(str) {
var l = str.length;
var buf = new ArrayBuffer(l*2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0; i<l; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
var veryLongStr = "ECMAScript [ECMA-262] has traditionally been used in contexts where there is no access to binary data. Where binary data has needed to be manipulated, it is often stored as a String and accessed using charCodeAt(), or stored as an Array with conversion to and from base64 for transmission. Both of these methods are slow and error-prone. For example, reading binary data as 32-bit integers requires manual conversion of 4 source bytes to and from the target type. Reading floating-point data is even more expensive. As web applications gain access to new functionality, working with binary data has become a much-demanded feature. Current specifications such as the File API [FILEAPI] and Web Sockets [WEBSOCKETS] would benefit from being able to read and write binary data directly in its native form. Specifications such as WebGL [WEBGL] require this functionality to meet acceptable performance characteristics. This specification defines a minimal set of functionality for accessing binary data from ECMAScript.";
Ready to run.
Test | Ops/sec | |
---|---|---|
Without variable |
| ready |
With variable |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.