Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
UUID methods
(version: 0)
Comparing performance of:
uuidv4 vs generateUUID
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function generateUUID() { // Public Domain/MIT var d = new Date().getTime(); //Timestamp var d2 = (performance && performance.now && (performance.now() * 1000)) || 0; //Time in microseconds since page-load or 0 if unsupported return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random() * 16; //random number between 0 and 16 if (d > 0) { //Use timestamp until depleted r = (d + r) % 16 | 0; d = Math.floor(d / 16); } else { //Use microseconds since page-load if supported r = (d2 + r) % 16 | 0; d2 = Math.floor(d2 / 16); } return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); }); } function uuidv4() { return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) ); }
Tests:
uuidv4
for (var i=0; i<10000; i++){ uuidv4(); }
generateUUID
for (var i=0; i<10000; i++){ generateUUID(); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
uuidv4
generateUUID
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.4 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 18 on iOS 18.4.1
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
uuidv4
11.3 Ops/sec
generateUUID
50.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Measuring the performance of different JavaScript libraries and approaches can be complex, but I'll break it down in an easy-to-understand manner. **Overview** The provided JSON benchmark compares two UUID (Universally Unique Identifier) generation methods: `generateUUID()` and `uuidv4()`. The tests are designed to measure the execution speed of each method. **Options compared** 1. **`generateUUID()`**: This is a custom implementation of UUID generation, as shown in the Script Preparation Code section. It uses a combination of timestamps (in milliseconds) and random numbers to generate a unique identifier. 2. **`uuidv4()`**: This is a widely used library function for generating Universally Unique Identifiers version 4 (UUID v4). It's designed to produce a high-quality, random UUID. **Pros and Cons** * `generateUUID()`: + Pros: Custom implementation allows for direct control over the generation process. + Cons: May have performance overhead due to the use of timestamps and manual calculations. * `uuidv4()`: + Pros: A widely used and well-maintained library function that's optimized for performance. + Cons: May require an external dependency (the `crypto` module) and may not provide direct control over the generation process. **Library: crypto** The `crypto` module is a built-in JavaScript library that provides various cryptographic functions, including random number generation. In this case, it's used by `uuidv4()` to generate a high-quality random UUID. **Special JS feature or syntax:** None mentioned in this benchmark. **Other alternatives** If you're interested in exploring alternative approaches, here are some options: * **`uuid()``: This is another widely used library function for generating Universally Unique Identifiers. It's similar to `uuidv4()`, but with some differences in its implementation. * **`Math.random()`**: You can use the built-in `Math.random()` function to generate a random number, which could be used to create a UUID. However, this approach may not produce as high-quality or unique identifiers as the library functions mentioned above. * **Custom implementation**: If you need more control over the UUID generation process, you could implement your own custom algorithm using JavaScript. This would require significant expertise in cryptography and random number generation. Keep in mind that while these alternatives exist, they might have different performance characteristics, security implications, or ease of use compared to the library functions mentioned above.
Related benchmarks:
create_UUID
UUID meth2odss1
sdgdsdgswUUID methods
UUID m21ethods
Comments
Confirm delete:
Do you really want to delete benchmark?