3 ms·
Using of array lookup is a bad wayof optimization: digittoval[src[N]] can take up to 200 cycles if not in cache Only synthetic tests that small enough (most of
by dmoldavanov 7y ago
Using of array lookup is a bad wayof optimization:
digittoval[src[N]] can take up to 200 cycles if not in cache
Only synthetic tests that small enough (most of them do nothing than tested code) show good results.
- LeifCarrotson 7y agoThe only reason that you'd want to optimize this function is if it's called frequently. Imagine you you have a text file or database with millions of numbers in ASCII hexadecimal notation. When parsing that data with this code, the table is practically guaranteed to be in the cache. Modern processors have 32 KB in L1 just 4 cycles away, hundreds of kB in L2 12 cycles away, and MB of L3 on-die cache which still only takes 50 cycles or so. I'd trust the machine to be certain to put this 256 byte table in L1. It would probably even pull the relevant parts (48-57 for the decimal digits and 65-70 for alphabetic) of a 65 KB 2-entry table if you were calling it in a tight loop. I'm curious if you could load it fast enough to sort out cache when working with a 4-entry, 4 GB table...
- dmoldavanov 7y ago>Imagine you you have a text file or database with millions of numbers in ASCII hexadecimal notation These much amount of data with guarantee will crowd out this array from cache bcauz processor cache in not a LRU
- dmoldavanov 7y agoAnd now imaging an Operation System with hundreds or even thousands other processes at work.
- ekimekim 7y agoI think the assumption is that you're interested in the behaviour in a tight loop where you're doing almost nothing else - that's generally the context in which this kind of tight optimizaton matters.