fast uid test (v3)

Revision 3 of this benchmark created on


Setup

"use strict";
    var fastuid = () => ("00000" + (Math.random()*Math.pow(36,5) << 0).toString(36)).slice(-5);
    
    var fastuid2a = () =>fastuid()+fastuid()+fastuid()+fastuid();
    
    var fastuid2b = () =>Array.apply(null, Array(4)).map(String.prototype.valueOf,("00000" + (Math.random()*Math.pow(36,5) << 0).toString(36)).slice(-5)).join();
    
    var fastuid3 = ()=>(1e20+'').replace(/[018]/g,a=>(a^Math.random()*16>>a/4).toString(16));
    
    var fastuidBis = () => {var fn = () => (Math.random()*Math.pow(36,5) << 0).toString(36); return ("0000000000" + fn()+fn()).slice(-10);}
    
    var fastuidLong = (a) => {"use strict";let n = '';var fn1 = (a) => {let n='';while (a--) {n+='00000'};return n}; var fn2 = (a) => {let n='';while (a--) {n+=(Math.random()*Math.pow(36,5) << 0).toString(36)};return n}; return (fn1(a)+fn2(a)).slice(a*5);}
    
    /* v2 */
    var fastuidLongv2 = (a) => {"use strict";let s = '';((a) => {while (a--) {s+='00000'}})(a); ((a) => {while (a--) {s+=(Math.random()*Math.pow(36,5) << 0).toString(36)}})(a); return (s).slice(a*5);}

Test runner

Ready to run.

Testing in
TestOps/sec
fastuid2a()
fastuid2a();
ready
fastuid3()
fastuid3();
ready
fastuid2b()
fastuid2b();
ready
fastuidBis()
fastuidBis();
ready
fastuidLong()
fastuidLong(2)
ready
fastuidLong(a lot)
fastuidLong(1000)
ready
fastuidLongv2()
fastuidLongv2(2)
ready
fastuidLongv2(a lot)
fastuidLongv2(1000)
ready

Revisions

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