MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / compiledEval

Function compiledEval

test/compute-engine/performance.test.ts:118–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

116}
117
118function compiledEval() {
119 const ce = new ComputeEngine();
120
121 const expr = ce.parse('ax^2+bx+c')!; // like $$ ax^2+bx+c $$
122 const vars = { a: 2, b: 3, c: 4 };
123
124 // Factor out substitution of constants
125 const expr3 = expr.subs(vars).N();
126
127 try {
128 const result = compile(expr3);
129 if (!result.run) throw new Error('fn is not a function');
130 const fn = result.run;
131 let y = 0;
132 const startTime = performance.now();
133 for (let x = 0; x <= Math.PI; x += 0.01) {
134 y += fn({ x });
135 }
136
137 return performance.now() - startTime;
138 } catch (e) {
139 console.error(e.message);
140 }
141 return 0;
142}
143
144describe.skip('Compute Engine modes', () => {
145 it('precise strict vs compiled', () => {

Callers 1

Calls 6

parseMethod · 0.95
compileFunction · 0.90
fnFunction · 0.85
NMethod · 0.65
subsMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected