Thread: Efficiency drain

  1. #1
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490

    Efficiency drain

    So I'm making changes to my Expression Manipulator program to allow more operators than the basic 4 and exponentiation. It basically uses a function that does a search and replace. ie:
    3+4^5
    becomes
    add(3,expt(4,5))

    The problem is that when deleting things in parentheses, after 5 of them, the program becomes horribly slow:
    (((x/y)/z)/a)/b -- around 2 seconds. another layer of parentheses makes it 6 seconds

    Is string manipulation really that time consuming? Or is it probably another piece of my program?

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    String manipulation can be fairly expensive, depending on the string implementation. If you are using substring operations alot, you might want to try SGI's STL (www.sgi.com/tech/stl) implementation, and the "rope" class. Its faster with substring operations, but slower on some more traditional ones.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #3
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    hehe... found out the reason...

    my test expression looks like this:
    ( ( ( 3 / 4 ) / 5 ) / 6 ) / 7

    Everything in parentheses is ignored, then parsed recursively. Everything seperated by a '/' sign is a Term.

    So I created a static int for the class Term and incremented it everytime a constructor was created. End result:
    54149

    With an extra layer of parentheses it became 415929. Add another layer:
    (((((3/4)/5)/6)/7)/8)/9

    2866334.

    Obviously 2.8 million Term objects where 20 would suffice is a problem...

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Lol I guess that would drain efficiency just a bit
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Just a couple orders of magnitude.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    Do you want to work for Microsofts XP team?

  7. #7
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Originally posted by Barjor
    Do you want to work for Microsofts XP team?
    Haha! Great one.


    Hang on a second though... There should only be (by my reckoning) twice the number of terms as delimiters... so 8, and 10... where are the other 3.2x10^93 coming from?
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  8. #8
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    There's some overlap... for instance there are four terms in ((x / y) / z): x, y, (x / y), and z

    But you're right, I have way too many objects... and I gotta search through code to find out why.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Efficiency with c++
    By pastitprogram in forum C++ Programming
    Replies: 17
    Last Post: 08-08-2008, 11:18 AM
  2. efficiency of a programming
    By sureshhewa in forum C Programming
    Replies: 7
    Last Post: 08-01-2008, 10:00 PM
  3. Calculating space efficiency using sizeof()
    By markcls in forum C Programming
    Replies: 6
    Last Post: 05-19-2007, 05:25 AM
  4. Binary tree search efficiency
    By ExCoder01 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-23-2003, 10:11 PM
  5. Algorithm Efficiency
    By supaben34 in forum C++ Programming
    Replies: 2
    Last Post: 10-12-2002, 06:45 PM