Quote:
Originally Posted by evinugur
|
This class is seriously inefficient. Suggestions:
-You are literally copying each value back an entry in the table with a For loop which is really really inefficient. A more efficient solution while still retaining the table of history would be to use a circular buffer where you set an arbitrary array index as the start and work back from there, looping around at one end to the other. Then, you can move the 'front' of the buffer forward and overwrite the oldest history element each time you sample the value. Then the process of inserting a sample requires only a memory write to a known array index, an increment of the circular buffer index, and a case to wrap it back to 0 at the end.
-It would be significantly more efficient to use a racheting error counter than a large RAM array which you For through each iteration. A racheting error counter woud use a single threshold on the current sample each time you sampled, and a counter of failures. A failure would increment the counter, a success would decrement the counter (limited to 0 and a number above your threshold). A certain counter value would be thresholded to declare stall. The comparison on the sample is only done once per sample (ever), instead of multiple times on the same sample, and the function call to read the stall state only has to perform a comparison on the counter. The reset is also simple, as you just set the counter to 0.