v8 optimizations trick B

Benchmark created by kogarashisan1 on


Setup

"Speed" + "you" + "JS" + "with" +
    "this" + "one" + "weird" + "trick";
    
    function mk(word) {
        var len = word.length;
        if (len > 255) return undefined;
        var i = len >> 2;
        return String.fromCharCode(
                (word.charCodeAt(    0) & 0x03) << 14 |
                (word.charCodeAt(    i) & 0x03) << 12 |
                (word.charCodeAt(  i+i) & 0x03) << 10 |
                (word.charCodeAt(i+i+i) & 0x03) <<  8 |
                len
        );
    }
    
    var MK = function() { };
    MK.prototype.mk = mk;
    var mker = new MK;

Test runner

Ready to run.

Testing in
TestOps/sec
function
var key;
key = mk('www.wired.com');
key = mk('www.youtube.com');
key = mk('scorecardresearch.com');
key = mk('www.google-analytics.com');
ready
method
var key;
key = mker.mk('www.wired.com');
key = mker.mk('www.youtube.com');
key = mker.mk('scorecardresearch.com');
key = mker.mk('www.google-analytics.com');
ready

Revisions

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

  • Revision 1: published by kogarashisan1 on