Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
UUID Test 3
(version: 2)
UUID speed validation tests
Comparing performance of:
old old vs new vs old crypt vs old crypt 2 vs old meth2 with random
Created:
7 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
function oldmeth() { function chr4 () { return Math.random().toString(16).slice(-4); } return `${chr4() + chr4()}-${chr4()}-${chr4()}-${chr4()}-${chr4()}${chr4()}${chr4()}`; } function oldmethcrypto() { function getRandom () { return crypto.getRandomValues(new Uint32Array(4)).reduce((prev, current) => `${prev.toString(16)}${current.toString(16)}`); } function update4(uuid) { const fourIndx = 12; return `${uuid.slice(0,12)}4${uuid.slice(13)}`; } function getEight(c) { return(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16); } function update8(uuid) { const eightIndx = 16; return `${uuid.slice(0,16)}${getEight(8)}${uuid.slice(17)}`; } function addDashes(uuid) { // xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx return `${uuid.slice(0,8)}-${uuid.slice(8,12)}-${uuid.slice(12,16)}-${uuid.slice(16,20)}-${uuid.slice(20)}`; } let uuid = getRandom(); uuid = update4(uuid); uuid = update8(uuid); uuid = addDashes(uuid); return uuid; } function oldmethcrypto2() { function getRandom () { return crypto.getRandomValues(new Uint32Array(4)).reduce((prev, current) => `${prev.toString(16)}${current.toString(16)}`); } function getEight(c) { return(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16); } let uuid = getRandom(); return `${uuid.slice(0,8)}-${uuid.slice(8,12)}-4${uuid.slice(13,16)}-${getEight(8)}${uuid.slice(17,20)}-${uuid.slice(20)}`; } function newmethrand1() { function getRandom (num) { let output; for(let i = 0; i < Math.ceil(num/8); i++) { output = `${output}${Math.random().toString(16).slice(-8)}`; } return output.slice(num * -1); } function getEight(c) { return(c ^ Math.random().toString(16).slice(-1) & 15 >> c / 4).toString(16); } let uuid = getRandom(32); return `${uuid.slice(0,8)}-${uuid.slice(8,12)}-4${uuid.slice(13,16)}-${getEight(8)}${uuid.slice(17,20)}-${uuid.slice(20)}`; } function newmeth() { return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16), ); }
Tests:
old old
oldmeth();
new
newmeth();
old crypt
oldmethcrypto();
old crypt 2
oldmethcrypto2();
old meth2 with random
newmethrand1();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
old old
new
old crypt
old crypt 2
old meth2 with random
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):
Measuring the performance of JavaScript code is crucial for optimizing and comparing different implementations. **Benchmark Definition** The provided JSON represents a benchmark definition, which outlines the characteristics of the test case: * Name: "UUID Test 3" * Description: "UUID speed validation tests" * Script Preparation Code: This section contains four JavaScript functions that generate a UUID (Universally Unique Identifier) in different ways. * `oldmeth`: This function uses the hexadecimal representation of random numbers to create a UUID. * `oldmethcrypto`: This function uses the crypto module to generate a UUID. It first generates four random 32-bit integers, concatenates them, and then updates and adds dashes to create the final UUID. * `oldmethcrypto2`: Similar to `oldmethcrypto`, but with some differences in the update and add-dashes logic. * `newmethrand1` and `newmeth`: These functions use a custom implementation of UUID generation using random numbers. **Individual Test Cases** The individual test cases are defined as follows: * `old old`: This test case uses the `oldmeth` function to generate a UUID. * `new`: This test case uses the `newmeth` function to generate a UUID. * `old crypt` and `old crypt 2`: These test cases use the `oldmethcrypto` and `oldmethcrypto2` functions, respectively, to generate UUIDs. * `old meth2 with random`: This test case uses the `newmethrand1` function to generate a UUID. **Latest Benchmark Result** The latest benchmark result shows the performance of each test case on Firefox 61 running on Windows: | Test Name | Executions Per Second | | --- | --- | | old crypt 2 | 113476.0625 | | old meth2 with random | 106844.390625 | | old crypt | 111633.7578125 | | old old | 15775.28125 | | new | 145212.59375 | **Analysis and Observations** Based on the benchmark results, we can observe: * The `oldmeth` function is significantly slower than the other implementations. * The `newmeth` function performs better than the `oldmethcrypto2` function. * The `old meth2 with random` function has a performance similar to the `newmeth` function. These observations suggest that the custom implementation of UUID generation in `newmethrand1` and `newmeth` is more efficient than the crypto-based implementations.
Related benchmarks:
UUID V4 Crypto vs Math
uuid generation crypto.getRandomValues
UUID Generator
Set string vs number
Comments
Confirm delete:
Do you really want to delete benchmark?