Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6592007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:29:56+00:00 2026-05-25T17:29:56+00:00

I sunk about a month of full time into a native C++ equation parser.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:29:56+00:00Added an answer on May 25, 2026 at 5:29 pm

    It’s hard to tell from your description if the slowness includes parsing, or it is just the interpretation time.

    The parser, if you write it as recursive-descent (LL1) should be I/O bound. In other words, the reading of characters by the parser, and construction of your parse tree, should take a lot less time than it takes to simply read the file into a buffer.

    The interpretation is another matter.
    The speed differential between interpreted and compiled code is usually 10-100 times slower, unless the basic operations themselves are lengthy.
    That said, you can still optimize it.

    You could profile, but in such a simple case, you could also just single-step the program, in the debugger, at the level of individual instructions.
    That way, you are “walking in the computer’s shoes” and it will be obvious what can be improved.

    Whenever I’m doing what you’re doing, that is, providing a language to the user, but I want the language to have fast execution, what I do is this:
    I translate the source language into a language I have a compiler for, and then compile it on-the-fly into a .dll (or .exe) and run that.
    It’s very quick, and I don’t need to write an interpreter or worry about how fast it is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just getting my teeth sunk into google maps API. I am attempting to plot
For another question, I'm running into a misconception that seems to arise here at
I've been using R for a little over a year now and it's been
I've got a class that has a read-only property defined that is actually a
Short database description Ships: The database of naval ships that took part in World
Battleship! Back in 2003 (when I was 17), I competed in a Battleship AI
This is almost identical to this question asked by another user, and is the
Report design, generation and maintenance isn't hard, but it is dull. We have a
I've got a standard UITableViewCell where I'm using the text and image properties to
What I'm trying to do is replicate the NSTokenField like UITextField seen in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.