Byte Manipulation

JavaScript performance comparison

Test case created by Si Robertson

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.

Testing in ArchiveTeam ArchiveBot 20190617.01.0 / Windows 7 0.0.0
Test Ops/sec
uint16_a
uint16_a( 10, 20 );
pending…
uint16_b
uint16_b( 10, 20 );
pending…
uint32_a
uint32_a( 10, 20, 30, 40 );
pending…
uint32_b
uint32_b( 10, 20, 30, 40 );
pending…
uint64_a
uint64_a( 10, 20, 30, 40, 50, 60, 70, 80 );
pending…
uint64_b
uint64_b( 10, 20, 30, 40, 50, 60, 70, 80 );
pending…

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

Compare results of other browsers

0 Comments