GUID / UUID in Javascript

Benchmark created by kelvin on


Preparation HTML

<script>
function guidGenerator() {
    var S4 = function() {
       return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
    };
    return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
function guidRender() {
    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);});
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
guidGenerator
guidGenerator();
ready
guidRender
guidRender();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by kelvin on
  • Revision 2: published by Fábio C. Barrionuevo da Luz on