Script Preparation code:
x
 
function uuidCrypto() {
  let bytes = window.crypto.getRandomValues(new Uint8Array(32));
  const randomBytes = () => (bytes = bytes.slice(1)) && bytes[0];
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => (c ^ randomBytes() & 15 >> c / 4).toString(16))
}
function uuidMath() {
                return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
                    const r = (Math.random() * 16) | 0;
                    const v = c === 'x' ? r : (r & 0x3) | 0x8;
                    return v.toString(16);
                });
}
function uuidCryptoNumber() {
  let bytes = window.crypto.getRandomValues(new Uint8Array(32));
  const randomBytes = () => (bytes = bytes.slice(1)) && bytes[0];
  return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => 
      (c ^ randomBytes() & 15 >> c / 4).toString(16)
    );
}
Tests:
  • math

     
    uuidMath()
  • crypto

     
    uuidCrypto()
  • crypto Number to String

     
    uuidCryptoNumber()
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    math
    crypto
    crypto Number to String

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one month ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Chrome 134 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
math 1304991.0 Ops/sec
crypto 266247.5 Ops/sec
crypto Number to String 301806.4 Ops/sec