KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I sunk about a month of full time into a native C++ equation parser. It works, except it is slow (between 30-100 times slower than a hard-coded equation). What can I change to make it faster? I read everything I could find on efficient code. In broad strokes: The parser converts a string equation expression into a list of "operation" objects. An operation object has two function pointers: a "getSource" and a "evaluate". To evaluate an equation, all I do is a for loop on the operation list, calling each function in turn. There isn't a single if / switch encountered when evaluating an equation - all conditionals are handled by the parser when it originally assigned the function pointers. I tried inlining all the functions to which the function pointers point - no improvement. Would switching from function pointers to functors help? How about removing the function pointer framework, and instead creating a full set of derived "operation" classes, each with its own virtual "getSource" and "evaluate" functions? (But doesn't this just move the function pointers into the vtable?) I have a lot of code. Not sure what to distill / post. Ask for some aspect of it, and ye shall receive.
Tags (comma-separated)
Save Edits
Cancel