3 ms·
I think, on a modern processor, a lookup table of 65k is way too big to be worthwhile for something as simple as a division memory access is relatively very sl
by Palomides 2y ago
I think, on a modern processor, a lookup table of 65k is way too big to be worthwhile for something as simple as a division
memory access is relatively very slow; OP probably should have benchmarked it
- Jerrrry 2y agoDepends on the use and context, benchmarking can hint at the "truth", that it is faster to just divide: ultimately the benchmark would have to have the two implementations and run them thru all possible inputs to know for sure. It may clearly state that memoization is slower, until you plop it into a benchmark that inlines division explicitly without using a given hardware accelerate. division by a constant input can be solved faster still, so there can be optimizations on top of memoization that would beat raw division on most peocessors/runtime environments.
- wongarsu 2y agoChances are only a small portion of the lookup table is used. It's conceivable that this is almost entirely L1 access. But I'm also very skeptical that this is actually faster. Would have been nice to see some numbers
- Palomides 2y agoI think an l2 cache hit is about the same number of cycles as a single byte divide, might as well save the cache for something else but yeah, this is just my speculation