Conversion to octet

JavaScript performance comparison

Test case created by FremyCompany

Info

What's the fastest way to convert any value to an octet?

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    window.input = (-5+10*Math.random()) | 0;
    window.output = 0;
    window.data = new DataView(new ArrayBuffer(1));
    window.tarr = new Uint8Array(window.data);
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Code conversion
window.output = +input & 255;
pending…
DataView conversion
data.setUint8(0,input);
window.output = data.getUint8(0);
pending…
Uint8Array conversion
window.output = (tarr[0]=input),tarr[0];
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment