Tests:
  • 1

    x
     
     function uuid() {
        let uuid = "",
            i,
            random;
        for (i = 0; i < 32; i++) {
            random = (Math.random() * 16) | 0;
            if (i == 8 || i == 12 || i == 16 || i == 20) {
                uuid += "-";
            }
            uuid += (i == 12 ? 4 : i == 16 ? (random & 3) | 8 : random).toString(16);
        }
        return uuid;
    }
    uuid();
  • 2

     
    const ui8a = new Uint8Array(1);
    function next() {
        let uuid = "", i;
        for (i = 0; i < 32; i++) {
            uuid += (i === 8 || i === 13 || i === 18 || i === 23) ? '-' : (crypto.getRandomValues(ui8a)[0] * 16) | 0;
        }
        return uuid;
    }
  • 3

     
    const ui8a = new Uint8Array(1);
    function next() {
        let uuid = [], i;
        for (i = 0; i < 32; i++) {
            uuid.push((i === 8 || i === 13 || i === 18 || i === 23) ? '-' : (crypto.getRandomValues(ui8a)[0] * 16) | 0);
        }
        return uuid.join('');
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    1
    2
    3

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.3 Safari/605.1.15
Safari 15 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
1 453142.0 Ops/sec
2 11848811.0 Ops/sec
3 11686905.0 Ops/sec