Thread: I need faster addition!

  1. #1
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161

    I need faster addition!

    hi,
    I'm sitting here watching my CPU go up,up,up all because of this:

    Code:
    float result[512];
    
    for(int i=0;i<sInputs;i++)
    {
           for(int ii=0;ii<512;ii++)
    	{
    		for(list[sInput].GoToRoot();list[sInput]..IsNotNull();list[sInput].Traverse)
    		{
    			result[ii] += list.value[ii];
    		}
    	}
    
    }
    ,which is some kind of pseudo-code trying to reflect what I need
    to do. When sInput is big this
    is really slow, soooo, anyone got any ideas conserning improvments?

    thanks a bunch
    /btq
    ...viewlexx - julie lexx

  2. #2
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161
    The only big win is to look at why you need to do this, and perhaps think of a better approach to the problem as a whole.
    these inputs are in fact audio-streams which need to be added
    together. There is no other way around that if you want
    to process say 30 different streams through the same filter.
    And I can't imagine it being more effective to apply a filter
    on each stream instead, and for some algorithms that
    is not even an option!. Ahh well, I'll keep tryin to find
    a better way

    thanks
    /btq
    ...viewlexx - julie lexx

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Would it be possible to calculate the results value as the data is read in and not wait for the whole list object to get populated and then need to use the for loop to calculate it? If you could do that, then you wouldn't need the extra loop? What is the structure of the loop object? Is it a class? How is the data input? Are you using the right type of data structure or container object for the job?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    julie lexx... btq's Avatar
    Join Date
    Jun 2002
    Posts
    161
    thanks for the help but after some experimenting
    it seems the only way to go is to ditch the nested loops.
    Seems to be the only way to get the effeiciency needed.
    The sad part is that it will introduce some limitations such
    as max 100 streams into one algorithm and a
    larger dll but I just don't see another way around it.

    thanks for the help though
    /btq
    ...viewlexx - julie lexx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Faster bitwise operator
    By Yarin in forum C++ Programming
    Replies: 18
    Last Post: 04-29-2009, 01:56 PM
  2. Faster way of printing to the screen
    By cacophonix in forum C Programming
    Replies: 16
    Last Post: 02-04-2009, 01:18 PM
  3. does const make functions faster?
    By MathFan in forum C++ Programming
    Replies: 7
    Last Post: 04-25-2005, 09:03 AM
  4. Addition vs. Multiplication
    By Unregistered in forum Game Programming
    Replies: 11
    Last Post: 07-10-2002, 11:24 AM
  5. Floating point faster than fixed-point
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-08-2001, 11:34 PM