|
-
November 28th, 2009, 04:29 AM
#4
Re: RMS an array
 Originally Posted by dommmm
now this should work right? however its possibly the least elegant piece of code ever plus it doesn't deal with a different bit width. any tips on how I could make this better? or make it work if it doesn't already?
There's a massive performance gain lying around in the second for loop. In each iteration of the outer loop you are using (bitWidth - 1) of the same elements for your average. Therefore, keeping a sum of squares and updating this in each loop will reduce the complexity from O(n * bitWidth) to O(n).
I would still advice though, that you first make sure you have the algorithm correct before you begin with such optimizations.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|