UUID-generators

JavaScript performance comparison

Revision 28 of this test case created by Bryan Elliott

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const hexRx = /[xN]/g;
  
  

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
UUID from template
const result = 'xxxxxxxx-xxxx-4xxx-Nxxx-xxxxxxxxxxxx'
  .replace(hexRx, (m) => (m === 'N'
    ? ((Math.random()*16)|0).toString(16)
    : ((Math.random()*4)|0 + 8).toString(16)
  ));
pending…
UUID using crypto API
const b = crypto.getRandomValues(new Uint16Array(8));
const d = [].map.call(b, a => a.toString(16).padStart(4, '0')).join('');
const vr = (((b[5] >> 12) & 3) | 8).toString(16);
const result = `${d.substr(0, 8)}-${d.substr(8, 4)}-4${d.substr(13, 3)}-${vr}${d.substr(17, 3)}-${d.substr(20, 12)}`;
pending…
UUID minimized randoms
let d = '';
while (d.length < 32) d += Math.random().toString(16).substr(2);
const vr = ((parseInt(d.substr(16, 1), 16) & 0x3) | 0x8).toString(16);
const result = `${d.substr(0, 8)}-${d.substr(8, 4)}-4${d.substr(13, 3)}-${vr}${d.substr(17, 3)}-${d.substr(20, 12)}`;
pending…
UUID from blob
const uuid = URL.createObjectURL(new Blob());
URL.revokeObjectURL(uuid);
const result = uuid.substr(uuid.length - 36);
pending…

Revisions

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

0 Comments