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

Function fastEval

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

Source from the content-addressed store, hash-verified

94}
95
96function fastEval() {
97 const ce = new ComputeEngine();
98
99 const expr = ce.parse('ax^2+bx+c')!; // like $$ ax^2+bx+c $$
100 const vars = { a: 2, b: 3, c: 4 };
101
102 // Factor out substitution of constants
103 const expr3 = expr.subs(vars).N();
104
105 ce.precision = 'machine';
106 ce.strict = false;
107
108 let y = 0;
109 const startTime = performance.now();
110 for (let x = 0; x <= Math.PI; x += 0.01) {
111 ce.assign('x', x);
112 y += Number(expr3.re);
113 }
114
115 return performance.now() - startTime;
116}
117
118function compiledEval() {
119 const ce = new ComputeEngine();

Callers 1

Calls 4

parseMethod · 0.95
assignMethod · 0.95
NMethod · 0.65
subsMethod · 0.65

Tested by

no test coverage detected