Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Test UUID with optimizations
(version: 0)
Comparing performance of:
1 vs 2 vs 3 vs 4 vs 5
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
1
const generateUUID = () => ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, e => // eslint-disable-next-line no-bitwise (e ^ ((window.crypto || window.msCrypto).getRandomValues(new Uint8Array(1))[0] & (15 >> (e / 4)))).toString(16) ); generateUUID();
2
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();
3
function uuid1(a) { return a ? (a ^ ((Math.random() * 16) >> (a / 4))).toString(16) : ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, uuid1); } uuid1()
4
var IDX=256, HEX=[], BUFFER; while (IDX--) HEX[IDX] = (IDX + 256).toString(16).substring(1); function v4() { var i=0, num, out=''; if (!BUFFER || ((IDX + 16) > 256)) { BUFFER = Array(i=256); while (i--) BUFFER[i] = 256 * Math.random() | 0; i = IDX = 0; } for (; i < 16; i++) { num = BUFFER[IDX + i]; if (i==6) out += HEX[num & 15 | 64]; else if (i==8) out += HEX[num & 63 | 128]; else out += HEX[num]; if (i & 1 && i > 1 && i < 11) out += '-'; } IDX++; return out; } v4();
5
const ui8a = new Uint8Array(1); var IDX=256, HEX=[], BUFFER = Array(IDX); while (IDX--) HEX[IDX] = (IDX + 256).toString(16).substring(1); function v4() { var i=0, num, out=''; if ((IDX + 16) > 256) { while (i--) BUFFER[i] = 256 * crypto.getRandomValues(ui8a)[0] | 0; i = IDX = 0; } for (; i < 16; i++) { num = BUFFER[IDX + i]; if (i==6) out += HEX[num & 15 | 64]; else if (i==8) out += HEX[num & 63 | 128]; else out += HEX[num]; if (i & 1 && i > 1 && i < 11) out += '-'; } IDX++; return out; } v4();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
1
2
3
4
5
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll explain the benchmark and its options in detail. **Overview** The benchmark is designed to measure the performance of different JavaScript functions that generate UUIDs (Universally Unique Identifiers). The test generates 32 hexadecimal digits, which are used to create a unique identifier. **Options compared** There are four different JavaScript functions that generate UUIDs: 1. `generateUUID` (Test Case 1) 2. `uuid` (Test Case 2) 3. `uuid1` (Test Case 3) 4. `v4` (Test Case 4) Each function generates a UUID in a slightly different way, which is reflected in the benchmark results. **Options analysis** * **generateUUID**: This function uses bitwise operations and a random number generator to generate a UUID. + Pros: Simple, efficient, and uses minimal resources. + Cons: May have security implications due to the use of `window.crypto` or `window.msCrypto`. * **uuid**: This function generates a UUID by concatenating 16 hexadecimal digits, separated by hyphens. + Pros: Easy to understand, simple implementation. + Cons: Less efficient than other options, as it requires more memory allocation and concatenation operations. * **uuid1**: This function is similar to `generateUUID`, but uses a different random number generator and some additional bitwise operations. + Pros: Similar performance profile to `generateUUID`, with improved security due to the use of a stronger random number generator. + Cons: More complex implementation than `generateUUID`. * **v4**: This function generates a UUID by using a pseudorandom number generator to select 16 hexadecimal digits from a pool of possible values. + Pros: Fast, efficient, and easy to understand. + Cons: May not be suitable for applications requiring high security or uniqueness guarantees. **Benchmark results** The benchmark results show the execution rate (executions per second) for each test case on different devices and browsers. The top-performing functions are: 1. `v4` (Test Case 4): Fastest performance across all devices and browsers. 2. `uuid1` (Test Case 3): Similar performance to `generateUUID`, with improved security due to the stronger random number generator. 3. `generateUUID` (Test Case 1): Fast performance, but may have security implications due to the use of `window.crypto` or `window.msCrypto`. 4. `uuid` (Test Case 2): Slower performance due to the need for concatenation operations and memory allocation. In summary, the benchmark highlights the trade-offs between security, efficiency, and implementation complexity when generating UUIDs in JavaScript.
Related benchmarks:
UUID perf test
testtestset
Test UUID with different optimizations
Set string vs number
Set string vs number #1
Comments
Confirm delete:
Do you really want to delete benchmark?