Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
UUID Generation
(version: 5)
Comparing performance of:
Jeff Ward v7 vs Jon Surrell (not real UUID) vs Broofa (new) vs Broofa (old) vs My Test vs Jeff Ward v7 window.crypto vs My Test v2 (array.join)
Created:
8 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
// Jeff Ward v7 var lut = []; for (var i=0; i<256; i++) { lut[i] = (i<16?'0':'')+(i).toString(16); } function e7() { var d0 = Math.random()*0xffffffff|0; var d1 = Math.random()*0xffffffff|0; var d2 = Math.random()*0xffffffff|0; var d3 = Math.random()*0xffffffff|0; return lut[d0&0xff]+lut[d0>>8&0xff]+lut[d0>>16&0xff]+lut[d0>>24&0xff]+'-'+ lut[d1&0xff]+lut[d1>>8&0xff]+'-'+lut[d1>>16&0x0f|0x40]+lut[d1>>24&0xff]+'-'+ lut[d2&0x3f|0x80]+lut[d2>>8&0xff]+'-'+lut[d2>>16&0xff]+lut[d2>>24&0xff]+ lut[d3&0xff]+lut[d3>>8&0xff]+lut[d3>>16&0xff]+lut[d3>>24&0xff]; } // Jeff Ward v7 window.crypto var lut = []; for (var i=0; i<256; i++) { lut[i] = (i<16?'0':'')+(i).toString(16); } function e7_crypto() { var d = new Uint32Array(4); window.crypto.getRandomValues(d); return lut[d[0]&0xff]+lut[d[0]>>8&0xff]+lut[d[0]>>16&0xff]+lut[d[0]>>24&0xff]+'-'+ lut[d[1]&0xff]+lut[d[1]>>8&0xff]+'-'+lut[d[1]>>16&0x0f|0x40]+lut[d[1]>>24&0xff]+'-'+ lut[d[2]&0x3f|0x80]+lut[d[2]>>8&0xff]+'-'+lut[d[2]>>16&0xff]+lut[d[2]>>24&0xff]+ lut[d[3]&0xff]+lut[d[3]>>8&0xff]+lut[d[3]>>16&0xff]+lut[d[3]>>24&0xff]; } // Broofa (new) function uuidv4_new() { return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) ) } // Broofa (old) function uuidv4_old() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } // Jon Surrell (not real UUID) function guid() { function s4() { return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1); } return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); } // My Test var UUID = (new function() { this._lut = []; for (var i = 0; i < 256; i++) { this._lut[i] = (i < 16 ? '0' : '') + (i).toString(16); }; this._format = function (rarr) { return '' + this._lut[rarr[0] & 0xff] + this._lut[rarr[0] >> 8 & 0xff] + this._lut[rarr[0] >> 16 & 0xff] + this._lut[rarr[0] >> 24 & 0xff] + '-' + this._lut[rarr[1] & 0xff] + this._lut[rarr[1] >> 8 & 0xff] + '-' + this._lut[rarr[1] >> 16 & 0x0f | 0x40] + this._lut[rarr[1] >> 24 & 0xff] + '-' + this._lut[rarr[2] & 0x3f | 0x80] + this._lut[rarr[2] >> 8 & 0xff] + '-' + this._lut[rarr[2] >> 16 & 0xff] + this._lut[rarr[2] >> 24 & 0xff] + this._lut[rarr[3] & 0xff] + this._lut[rarr[3] >> 8 & 0xff] + this._lut[rarr[3] >> 16 & 0xff] + this._lut[rarr[3] >> 24 & 0xff]; }; this._getRandomness = function () { if ('crypto' in window && 'Uint32Array' in window) { var dvals = new Uint32Array(4); window.crypto.getRandomValues(dvals); return dvals } return [ Math.random() * 0x100000000 >>> 0, Math.random() * 0x100000000 >>> 0, Math.random() * 0x100000000 >>> 0, Math.random() * 0x100000000 >>> 0, ]; }; this.generate = function () { return this._format(this._getRandomness()); }; }()); var UUID2 = (new function () { this._lut = []; for (var i = 0; i < 256; i++) { this._lut[i] = (i < 16 ? '0' : '') + (i).toString(16); }; this._format = function (rarr) { return [ this._lut[rarr[0] & 0xff] , this._lut[rarr[0] >> 8 & 0xff] , this._lut[rarr[0] >> 16 & 0xff] , this._lut[rarr[0] >> 24 & 0xff] , '-' , this._lut[rarr[1] & 0xff] , this._lut[rarr[1] >> 8 & 0xff] , '-' , this._lut[rarr[1] >> 16 & 0x0f | 0x40] , this._lut[rarr[1] >> 24 & 0xff] , '-' , this._lut[rarr[2] & 0x3f | 0x80] , this._lut[rarr[2] >> 8 & 0xff] , '-' , this._lut[rarr[2] >> 16 & 0xff] , this._lut[rarr[2] >> 24 & 0xff] , this._lut[rarr[3] & 0xff] , this._lut[rarr[3] >> 8 & 0xff] , this._lut[rarr[3] >> 16 & 0xff] , this._lut[rarr[3] >> 24 & 0xff] ].join('') }; this._getRandomness = function () { if ('crypto' in window && 'Uint32Array' in window) { var dvals = new Uint32Array(4); window.crypto.getRandomValues(dvals); return dvals } return [ Math.random() * 0x100000000 >>> 0, Math.random() * 0x100000000 >>> 0, Math.random() * 0x100000000 >>> 0, Math.random() * 0x100000000 >>> 0, ]; }; this.generate = function () { return this._format(this._getRandomness()); }; }());
Tests:
Jeff Ward v7
e7();
Jon Surrell (not real UUID)
guid();
Broofa (new)
uuidv4_new();
Broofa (old)
uuidv4_old();
My Test
UUID.generate();
Jeff Ward v7 window.crypto
e7_crypto();
My Test v2 (array.join)
UUID2.generate();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (7)
Previous results
Fork
Test case name
Result
Jeff Ward v7
Jon Surrell (not real UUID)
Broofa (new)
Broofa (old)
My Test
Jeff Ward v7 window.crypto
My Test v2 (array.join)
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):
Based on the provided benchmark results, I'll provide an analysis of the performance differences between each test case. **Comparison** 1. **Jeff Ward v7 vs Jon Surrell (not real UUID)**: The test with "Jeff Ward v7" has a significantly higher execution rate per second (5307091.5 vs 3778559.5). This suggests that the original implementation of UUID generation in JavaScript has been optimized, and the new version is not yet as efficient. 2. **Jeff Ward v7 vs Jeff Ward v7 window.crypto**: The test with "Jeff Ward v7 window.crypto" has a significantly lower execution rate per second (957315.125). This suggests that using `window.crypto` for UUID generation provides better performance than the original implementation. 3. **My Test vs My Test v2 (array.join)**: The test with "My Test v2 (array.join)" has a higher execution rate per second (598290.3125) compared to the original "My Test" implementation (687829.4375). This suggests that the new version of UUID generation in JavaScript is more efficient. 4. **Broofa (new) vs Broofa (old)**: The test with "Broofa (new)" has a lower execution rate per second (46052.7890625) compared to the original "Broofa (old)" implementation (551484.0). This suggests that the new version of UUID generation in JavaScript is more efficient. 5. **Jeff Ward v7 vs Jon Surrell (not real UUID)**: The test with "Jon Surrell (not real UUID)" has a lower execution rate per second compared to both "Jeff Ward v7" and "My Test". This suggests that the non-real UUID implementation may have some performance overhead. **Conclusion** The new version of UUID generation in JavaScript appears to be more efficient than the original implementation. The `window.crypto` variant provides even better performance, suggesting it is a good choice for generating UUIDs. The comparison between different implementations and variants highlights the importance of optimizing library code and considering the use of window.crypto for improved performance.
Related benchmarks:
UUID Generation (compatibility mode)
UUID Generation 2
UUID V4 Crypto vs Math
UUID Generation (compatibility mode) (fork)
Comments
Confirm delete:
Do you really want to delete benchmark?