Optimization stuff

This is a discussion on Optimization stuff within the C++ Programming forums, part of the General Programming Boards category; This post is aimed at anyone looking for optimization techniques. I am planning on making some other optimization programs, but ...

  1. #1
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903

    Optimization stuff

    This post is aimed at anyone looking for optimization techniques. I am planning on making some other optimization programs, but for now I'll just upload the one that I have done.

    The method I am going to show is to prove how much faster it is to use a for loop with strlen precalculated BEFORE the loop.

    Many programs have the loop look something like this:

    for(int a=0;a<strlen(someString);a++)

    and a lot of people put that code in to their program without realizing how much of a bottleneck it is. Most people who have been programming for a while will/should hopefully notice this at some point or another, that's why I'm aiming this post more at beginners.

    So anyways, I made a program that basically shows how much faster it is to preprocess the length of the string beforehand. I get about a 140x increase in speed when i use the precalculated method.

    And again, I am aiming this post at anyone who is either new to programming and looking towards optimizations or even people who might have just overlooked this. I understand that this is an extremely simple program, so please don't start a flame war over it or something
    Attached Files Attached Files

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    It can also be applied to any other situation where a function is called a number of times, with the same result being returned each time. Also, mathematical calculations done within a loop could be done before hand instead.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  3. #3
    Registered User big146's Avatar
    Join Date
    Apr 2003
    Posts
    74

    Wow

    Thks for the info. I am a noob so this is good to know. I ran the program and saw the diff.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Turn Off Optimization?
    By danlee58 in forum C Programming
    Replies: 6
    Last Post: 12-10-2008, 02:52 AM
  2. need reading material for c++ database optimization
    By elninio in forum C++ Programming
    Replies: 0
    Last Post: 07-24-2008, 11:32 PM
  3. Tab key stuff. C+WinAPI is killing me. Please help.
    By Templario in forum Windows Programming
    Replies: 5
    Last Post: 11-21-2002, 02:35 PM
  4. arguments, directories and stuff...
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 06-26-2002, 05:46 PM
  5. Your stuff
    By smog890 in forum C Programming
    Replies: 6
    Last Post: 06-13-2002, 11:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21