This page was last modified 2008-04-23 15:07:20 by Puchu.Net user Choco. (Show history)
I learned several years ago from school that modulus operations ( Very often I need to map a moving window to a data stream, and require a way to calculate the offset within that window using modulus operations. For example, the position in the stream modulo the size of the access window, when maintaining a FIFO/buffer as temporary storage. [edit] Alternatives For This ExperimentInstead of calculating the offset every time using
versus using modulus:
The difference is one requiring branching and the other modulus operation. [edit] Experiment ResultsWith some test code, I am able to produce some timing data (in seconds) involving functions that use one of the two methods described earlier:
This is profiled on a quad-core computer over a 128MB data set, producing exactly the same output. The code path using modulus operation is taking about 12% more time to execute. Although more code is necessary to achieve the same results without using
|
|
||||||||||||||||||||||||