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
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/sval@0.6.3/dist/sval.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/expr-eval@2.0.2/dist/bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/mathjs@12.4.1/lib/browser/math.js"></script>
// Create shared context
const context = {
c_6853e66dffb3392513d4f9bb: '19998269322',
c_6853e66dffb3392513d4f9bc: 'KERBR00043981',
c_6853e66dffb3392513d4f9bd: '584',
c_6853e66dffb3392513d4f9be: '01/02/2024 T5:23:51 AM GMT',
c_6853e66dffb3392513d4f9bf: 'Sprinklr',
c_6853e66dffb3392513d4f9c0: 'Brazil',
c_6853e66dffb3392513d4f9c1: '5519998269322', };
const expression = 'c_6853e66dffb3392513d4f9bd > 600 ? "High" : "Low"';
const evalExpression = '584 > 600 ? "High" : "Low"';
// Function to evaluate with Sval without AST caching
const interpreter = new Sval({
ecmaVer: 11,
sourceType: "script",
sandBox: true,
});
interpreter.import(context);
const runSvalWithoutASTCaching = (expr) => {
interpreter.run(`exports.__output__ = ${expr}`);
return interpreter.exports.__output__;
}
// Function to evaluate with Sval with AST caching
const ASTMapCache = new Map();
const interpreterwithCaching = new Sval({
ecmaVer: 11,
sourceType: "script",
sandBox: true,
});
interpreterwithCaching.import(context);
const runSvalWithASTCaching = (expression) => {
const svalScript = `exports.__output__ = ${expression}`;
if (!ASTMapCache.has(svalScript)) {
ASTMapCache.set(svalScript, interpreterwithCaching.parse(svalScript));
}
interpreterwithCaching.run(ASTMapCache.get(svalScript));
}
// Expr-Eval
const exprEvalParser = new window.exprEval.Parser();
const exprEvalAst = exprEvalParser.parse(expression);
const runExprEval = () => {
return exprEvalAst.evaluate(context);
}
// Using Math.js
const runMathJS = (expression) => {
const mathjsCompiled = math.compile(expression);
return mathjsCompiled.evaluate(context);
}
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| eval | | ready |
| Sval without AST caching | | ready |
| Sval with AST caching | | ready |
| Math.js | | ready |
| Expr-eval | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.