| 116 | } |
| 117 | |
| 118 | function 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 | |
| 144 | describe.skip('Compute Engine modes', () => { |
| 145 | it('precise strict vs compiled', () => { |