UUID golf (v13)

Revision 13 of this benchmark created by r on


Setup

build = function(a,b){for(b=a='';a++<36;b+=~a%5|a*3&4?(a^15?8^Math.random()*(a^20?16:4):4).toString(16):'-');return b}
    
    replace = function b(a){return a?(a^Math.random()*16>>a/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,b)}
    
    // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
    stackoverflow2117523 = function() {'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);
    });}
    
    // stolen from http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
    stackoverflow105034 = function () {
        var s4 = function () {
            return Math.floor((1 + Math.random()) * 0x10000)
                      .toString(16)
                      .substring(1);
        };
        return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
                           s4() + '-' + s4() + s4() + s4();
    }

Test runner

Ready to run.

Testing in
TestOps/sec
build()
build()
ready
replace()
replace()
ready
stackoverflow answer #2117523
stackoverflow2117523()
ready
stackoverflow top answer 105034
stackoverflow105034()
ready

Revisions

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