I may be wrong, but it looks like when you call expression.evaluate({ x: 1 }), it compiles it into a JS function every time before evaluating. Is it possible to compile the expression just once and then call evaluate many times on the compiled function, passing in different values for x? This would make it much faster than compiling every time.
The equivalent math.js workflow would be:
const node = math.parse(expr) // parse expression into a node tree
const code = node.compile() // compile the node tree
const result = code.evaluate([scope]) // evaluate the code with an optional scope
where the final evaluate could be called multiple times without recompiling.
I may be wrong, but it looks like when you call
expression.evaluate({ x: 1 }), it compiles it into a JS function every time before evaluating. Is it possible to compile the expression just once and then call evaluate many times on the compiled function, passing in different values forx? This would make it much faster than compiling every time.The equivalent math.js workflow would be:
where the final
evaluatecould be called multiple times without recompiling.