Byte Manipulation
JavaScript performance comparison
Preparation code
<script>
x8 = 0x100;
x16 = 0x10000;
x24 = 0x1000000;
x32 = 0x100000000;
x40 = 0x10000000000;
x48 = 0x1000000000000;
x56 = 0x100000000000000;
// these are here to make the tests fair
s8 = 8;
s16 = 16;
s24 = 24;
s32 = 32;
s40 = 40;
s48 = 48;
s56 = 56;
function uint16_a( a, b ) {
return ( a << s8 | b );
}
function uint16_b( a, b ) {
return ( a * x8 + b );
}
function uint32_a( a, b, c, d ) {
return ( a << s24 | b << s16 | c << s8 | d );
}
function uint32_b( a, b, c, d ) {
return ( a * x24 + b * x16 + c * x8 + d );
}
function uint64_a( a, b, c, d, e, f, g, h ) {
return ( a << s56 | b << s48 | c << s40 | d << s32 | e << s24 | f << s16 | g << s8 | h );
}
function uint64_b( a, b, c, d, e, f, g, h ) {
return ( a * x56 + b * x48 + c * x40 + d * x32 + e * x24 + f * x16 + g * x8 + h );
}
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
|
uint16_a
|
|
pending… |
|
uint16_b
|
|
pending… |
|
uint32_a
|
|
pending… |
|
uint32_b
|
|
pending… |
|
uint64_a
|
|
pending… |
|
uint64_b
|
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 Comments