SI
SI
discoversearch

We've detected that you're using an ad content blocking browser plug-in or feature. Ads provide a critical source of revenue to the continued operation of Silicon Investor.  We ask that you disable ad blocking while on Silicon Investor in the best interests of our community.  If you are not using an ad blocker but are still receiving this message, make sure your browser's tracking protection is set to the 'standard' level.
Technology Stocks : Advanced Micro Devices - Moderated (AMD) -- Ignore unavailable to you. Want to Upgrade?


To: Joe NYC who wrote (64998)12/5/2001 5:07:48 PM
From: TGPTNDRRead Replies (1) | Respond to of 275872
 
Joe, Re: <but my recollection is that hash table, the order of magnitude of the time to evaluate n cases is 1, meaning a fixed time.>

That's about a 30K' view. Order of magnitude 1 would cover values from 1 to 9 or 900% range. In the program we're talking about the compiler can figure exactly the table size so it should be able to figure out how to index directly without a hash. But that's the kind of reason why you have to look at the machine code(as first choice) or the .asm(for a good clue). Stupid compilers may build a stupid lookup -- and that's why well hand assembled code will outrun straight C every time(sometimes by factors of 1000s).

tgptndr



To: Joe NYC who wrote (64998)12/5/2001 6:33:57 PM
From: Neil BoothRead Replies (1) | Respond to of 275872
 
I don't know how the case statement is compiled to assembler.

GCC orders the cases in a binary tree. It then creates a
set of if / then / else branches to get to the right conclusion as efficiently as possible.

Further, any subsets of the tree that are dense get done by
a jump table. Thus a single case statement can be translated into 0, 1 or many jump tables. GCC is pretty good at that kind of thing; other compilers often not as good.

Neil.