()
| 94 | } |
| 95 | |
| 96 | function 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 | |
| 118 | function compiledEval() { |
| 119 | const ce = new ComputeEngine(); |
no test coverage detected