Skip to content

Commit 80027e7

Browse files
committed
Add cel-js benchmark
1 parent ae86778 commit 80027e7

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,9 @@ console.log(await bundle('main.js', {
169169
<!-- * [glsl-transpiler](https://github.com/stackgl/glsl-transpiler) -->
170170
<!-- * [piezo](https://github.com/dy/piezo) -->
171171

172-
<!--
173-
## Refs
174172

175-
[jsep](https://github.com/EricSmekens/jsep), [jexl](https://github.com/TomFrost/Jexl), [expr-eval](https://github.com/silentmatt/expr-eval), [math.js](https://mathjs.org/).
173+
## Alternatives
176174

177-
[mozjexl](https://github.com/mozilla/mozjexl), [jexpr](https://github.com/justinfagnani/jexpr), [expression-eval](https://github.com/donmccurdy/expression-eval), [string-math](https://github.com/devrafalko/string-math), [nerdamer](https://github.com/jiggzson/nerdamer), [math-codegen](https://github.com/mauriciopoppe/math-codegen), [math-parser](https://www.npmjs.com/package/math-parser), [nx-compile](https://github.com/nx-js/compiler-util), [built-in-math-eval](https://github.com/mauriciopoppe/built-in-math-eval) -->
175+
[cel-js](https://github.com/marcbachmann/cel-js?tab=readme-ov-file), [jsep](https://github.com/EricSmekens/jsep), [jexl](https://github.com/TomFrost/Jexl), [expr-eval](https://github.com/silentmatt/expr-eval), [math.js](https://mathjs.org/), [mozjexl](https://github.com/mozilla/mozjexl), [jexpr](https://github.com/justinfagnani/jexpr), [expression-eval](https://github.com/donmccurdy/expression-eval), [string-math](https://github.com/devrafalko/string-math), [nerdamer](https://github.com/jiggzson/nerdamer), [math-codegen](https://github.com/mauriciopoppe/math-codegen), [math-parser](https://www.npmjs.com/package/math-parser), [nx-compile](https://github.com/nx-js/compiler-util), [built-in-math-eval](https://github.com/mauriciopoppe/built-in-math-eval)
178176

179177
<p align=center><a href="https://github.com/krsnzd/license/">ॐ</a></p>

test/benchmark.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const ctx = {
1313
f: { g: [x => x + 1] }, h: 10, i: { j: 20 }
1414
};
1515

16+
// CEL-compatible expression (CEL uses BigInt, no function calls on array elements)
17+
const celExpr = `a + b * c - d / e + f.g[0] + i.j`;
18+
const celCtx = { a: 1n, b: 2n, c: 3n, d: 4n, e: 5n, f: { g: [11n] }, i: { j: 20n } };
19+
1620
const bench = (name, fn) => {
1721
// Warmup
1822
for (let i = 0; i < 1000; i++) fn();
@@ -121,6 +125,13 @@ async function run() {
121125
results.parse['angular-expr'] = bench('angular-expr', () => ae.compile(expr));
122126
} catch (e) { console.log('angular-expr: SKIP -', e.message); }
123127

128+
// @marcbachmann/cel-js
129+
try {
130+
const { parse: celParse } = await cdn('@marcbachmann/cel-js');
131+
celParse(celExpr);
132+
results.parse['cel-js'] = bench('cel-js', () => celParse(celExpr));
133+
} catch (e) { console.log('cel-js: SKIP -', e.message); }
134+
124135
console.log('\n=== EVAL ===\n');
125136

126137
// subscript compile (js)
@@ -188,6 +199,14 @@ async function run() {
188199
results.eval['angular-expr'] = bench('angular-expr', () => fn(ctx));
189200
} catch (e) { console.log('angular-expr: SKIP -', e.message); }
190201

202+
// @marcbachmann/cel-js
203+
try {
204+
const { parse: celParse } = await cdn('@marcbachmann/cel-js');
205+
const celFn = celParse(celExpr);
206+
celFn(celCtx);
207+
results.eval['cel-js'] = bench('cel-js', () => celFn(celCtx));
208+
} catch (e) { console.log('cel-js: SKIP -', e.message); }
209+
191210
// Summary
192211
console.log('\n=== SUMMARY ===\n');
193212

0 commit comments

Comments
 (0)