jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
/* nested ternary */
function testTernary(operand, value)
{
var rxStr = operand === '=='
? '^' + value + '$'
: operand === '^='
? '^' + value
: operand === '$='
? value + '$'
: operand === '~='
? '\\b' + value + '\\b'
: operand === '*='
? value
: null;
return rxStr;
}
/* if/else */
function testIf(operand, value)
{
var rxStr;
if (operand === '==') rxStr = '^' + value + '$';
else if (operand === '^=') rxStr = '^' + value;
else if (operand === '$=') rxStr = value + '$';
else if (operand === '~=') rxStr = '\\b' + value + '\\b';
else if (operand === '*=') rxStr = value;
return rxStr;
}
/* switch with early-exit */
function testSwitchEarly(operand, value)
{
switch(value)
{
case '==' : return '^' + value + '$';
case '^=' : return '^' + value;
case '$=' : return value + '$';
case '~=' : return '\\b' + value + '\\b';
case '*=' : return value;
}
return;
}
/* switch with early-exit */
function testSwitchLate(operand, value)
{
var rxStr;
switch(value)
{
case '==':
rxStr = '^' + value + '$';
break;
case '^=':
rxStr = '^' + value;
break;
case '$=':
rxStr = value + '$';
break;
case '~=':
rxStr = '\\b' + value + '\\b';
break;
case '*=':
rxStr = value;
break;
}
return rxStr;
}
/* object with values calculated each time */
function testObj(operand, value)
{
var operands =
{
'==' : '^' + value + '$',
'$=' : value + '$',
'^=' : '^' + value,
'~=' : '\\b' + value + '\\b',
'*=' : value
};
return operands[operand];
}
/* object with values calculated by a function, declared each time */
function testLazyObjInt(operand, value)
{
var operands =
{
'==' : function(){ return '^' + value + '$'; },
'^=' : function(){ return '^' + value; },
'$=' : function(){ return value + '$'; },
'~=' : function(){ return '\\b' + value + '\\b'; },
'*=' : function(){ return value; }
};
if(operand in operands)
{
return operands[operand]();
}
return;
}
/* object with values calculated by a function, declared once */
function testLazyObjExt(operand, value)
{
if(operand in operands)
{
return operands[operand](value);
}
return;
}
var operands =
{
'==' : function(value){ return '^' + value + '$'; },
'^=' : function(value){ return '^' + value; },
'$=' : function(value){ return value + '$'; },
'~=' : function(value){ return '\\b' + value + '\\b'; },
'*=' : function(value){ return value; }
};
var ops = ['==', '^=', '$=', '~=','!='];
Ready to run.
Test | Ops/sec | |
---|---|---|
ternary |
| ready |
if |
| ready |
switch (early exit) |
| ready |
switch (late exit) |
| ready |
calculate all values |
| ready |
get value from function (internal) |
| ready |
get value from function (global) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.