I have a method which summarizes a collection of decimal values using a method similar to this...
Dim _amountCollection as New List(Of Decimal)
_amountCollection.Add(145.12D)
_amountCollection.Add(11.32D)
_amountCollection.Add(6547.07D)
Dim _totalAmount as Decimal
For Each _individualAmount as Decimal in _amountCollection
_totalAmount += _individualAmount
Next
In the actual code, there are usually more members in the amount collection, and there are at least 50 individual amount collections that need to be summed in a total operation.
This recalculation of total amount gets called often (at least once, and then again for each collection content change), and is showing up in profile traces as consuming between 2-5% of the total operation time. I am looking to see if anyone has an idea of how to speed this summation operation up, or if this is just the fastest its going to get.
Caching is not realistic in this case, because the amounts must be recalculated.
**EDIT For Ravadre and Joel - The total amount is stored at the class level (each amount collection and sum are contained in a class instance)
Any ideas?