tpl-recognizer

Benchmark created by Don Griffin on


Setup

function doTpl (x) {
        // do nothing
    }
    
    function doExpr (x) {
        // do nothing
    }
    
    var tpl = 'Hello {foo.bar}';
    var notpl = 'Hello world';
    
    function usingIndexOf (s) {
        if (s.indexOf('{') < 0) {
            doExpr(s);
        } else {
            doTpl(s);
        }
    }
    
    var regex = /\{/;
    function usingRegExp (s) {
        if (regex.test(s)) {
            doExpr(s);
        } else {
            doTpl(s);
        }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf
usingIndexOf(tpl);
usingIndexOf(notpl);
 
ready
regexp
usingRegExp(tpl);
usingRegExp(notpl);
 
ready

Revisions

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

  • Revision 1: published by Don Griffin on