UUID golf (v12)

Revision 12 of this benchmark created by imma on


Description

added subcache - cache the sub-function so it's not (potentially) recreated each time

Setup

build1 = function(a,b){for(b=a='';a++<24;b+=~a%5|a*3&4?(a^15?8^Math.random()*(a^20?16:4):4).toString(16):'-');return b+((new Date().valueOf()*(~~(Math.random()+1)*16)).toString(16))}
    
    replace = function b(a){return a?(a^Math.random()*16>>a/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,b)}
    
    another = function(){return"00000000-0000-4000-8000-000000000000".replace(/0/g,function(){return(0|Math.random()*16).toString(16)})}
    
    sub = function () {
    var s=function(){return (((1+Math.random())*0x10000)|0).toString(16).substring(1);},r=[8,9,"a","b"]
    return (s()+s()+"-"+s()+"-4"+s().substr(0,3)+"-"+r[Math.floor(Math.random()*4)]+s().substr(0,3)+"-"+s()+s()+s())
    }
    
    subcache = function (r,s) {
    return function(){return (s()+s()+"-"+s()+"-4"+s().slice(1)+"-"+r[Math.floor(Math.random()*4)]+s().slice(1)+"-"+s()+s()+s())
    }}([8,9,"a","b"],function(){return (((1+Math.random())*0x10000)|0).toString(16).slice(1)});
    
    build2 = function(a,b){for(b=a='';a++<36;b+=a*51&52?(a^15?8^Math.random()*(a^20?16:4):4).toString(16):'-');return b}

Test runner

Ready to run.

Testing in
TestOps/sec
build1()
build1()
ready
replace()
replace()
ready
another()
another()
ready
sub()
sub()
ready
build2()
build2()
ready
subcache()
subcache()
ready

Revisions

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