If you wanted to eek out a little more speed, you can do a "circular buffer". Use a fixed size array, keep advancing the index by one, and that index is both the "head" and the "tail". This could very well be slower, or faster, I am not familiar with the Java implementations. In C this would be noticeably faster. The LinkedList is slightly easier to implement and explain, so that was why I suggested it first.
On Sun, Aug 9, 2009 at 11:35 PM, Eugene Kononov <[email protected]>wrote: > > Ahh yes, this way is much slicker, thanks for the example. I've >> updated the regression fit if anyone is interested: >> >> http://groups.google.com/group/jbooktrader/web/RegressionSlope.java >> >> > > For better results, only calculate value when inside this: > if (historyList.size() > nDataPoints) {...} > Otherwise, the calculated slope would take some wild values when the number > of samples is low. > > > >> Quick coding question here, is there any reason to use a linked list >> instead of array list here? Probably not much of a difference, I >> would guess. >> >> > Removing the first element from an ArrayList is very expensive, because all > the other elements need to be shifted up. Removing the first element from a > LinkedList is cheap, because it simply moves the "head" pointer. On the > other hand, adding elements to LinkedList is probably slower than adding > elements to ArrayList. Best way to find out is to to time the same > optimization job with both ArrayList and LinkedList, and compare the > results. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "JBookTrader" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/jbooktrader?hl=en -~----------~----~----~----~------~----~------~--~---
