atom feed40 messages in org.codehaus.groovy.userRE: [groovy-user] Acceptable Placemen...
FromSent OnAttachments
Randall R SchulzDec 3, 2007 3:41 pm 
Stand TrooperDec 3, 2007 4:03 pm 
Randall R SchulzDec 3, 2007 4:07 pm 
Stand TrooperDec 3, 2007 4:34 pm 
Russel WinderDec 3, 2007 9:46 pm 
Russel WinderDec 3, 2007 9:49 pm 
Charles Oliver NutterDec 3, 2007 9:52 pm 
Randall R SchulzDec 3, 2007 10:10 pm 
Jochen TheodorouDec 4, 2007 5:59 am 
Charles Oliver NutterDec 4, 2007 10:59 am 
Jochen TheodorouDec 4, 2007 11:51 am 
Smith, Jason, CTR, OASD(HA)/TMADec 4, 2007 1:10 pm 
Charles Oliver NutterDec 4, 2007 1:24 pm 
Charles Oliver NutterDec 4, 2007 1:29 pm 
Jochen TheodorouDec 4, 2007 1:54 pm 
Smith, Jason, CTR, OASD(HA)/TMADec 4, 2007 2:33 pm 
Jochen TheodorouDec 4, 2007 2:44 pm 
Charles Oliver NutterDec 4, 2007 2:56 pm 
Smith, Jason, CTR, OASD(HA)/TMADec 5, 2007 6:35 am 
Charles Oliver NutterDec 5, 2007 10:16 am 
Smith, Jason, CTR, OASD(HA)/TMADec 5, 2007 10:29 am 
Jochen TheodorouDec 5, 2007 5:45 pm 
Jochen TheodorouDec 7, 2007 8:31 am 
Randall R SchulzDec 7, 2007 8:37 am 
Jochen TheodorouDec 7, 2007 8:49 am 
Guillaume LaforgeDec 7, 2007 9:01 am 
Jochen TheodorouDec 7, 2007 9:14 am 
Guillaume LaforgeDec 7, 2007 9:16 am 
Randall R SchulzDec 7, 2007 9:22 am 
Guillaume LaforgeDec 7, 2007 9:28 am 
Charles Oliver NutterDec 7, 2007 10:09 am 
Charles Oliver NutterDec 7, 2007 10:11 am 
Randall R SchulzDec 7, 2007 10:18 am 
Jochen TheodorouDec 7, 2007 10:31 am 
Charles Oliver NutterDec 7, 2007 12:23 pm 
Randall R SchulzDec 7, 2007 12:37 pm 
Charles Oliver NutterDec 7, 2007 1:35 pm 
Randall R SchulzDec 7, 2007 1:40 pm 
Gavin GroverDec 7, 2007 11:49 pm 
Jochen TheodorouDec 8, 2007 3:40 am 
Subject:RE: [groovy-user] Acceptable Placement of default: Within Switch?
From:Smith, Jason, CTR, OASD(HA)/TMA (Jaso@tma.osd.mil)
Date:Dec 4, 2007 1:10:21 pm
List:org.codehaus.groovy.user

Charlie, I believe you are misusing Big O notation in this case. For small values of n, the constants outweigh the multiplier. 10 * log(4) is greater than 1 * (4). What you are saying is absolutely true if your switch statements end up being 50 or 100 or 500 statements long, assuming that a binary or hash search can be used in such extreme cases. But for a set of simple comparisons, say, 10 long, your average case will be 5 (big assumption). Is that faster than 3 or 4 comparisons, plus associated overhead? The hash code is probably faster (maybe - that's an amortized analysis), but there is still overhead there.

I could be convinced otherwise. For practical purposes, I would have to see benchmarks in regular production apps that showed this was a significant part of execution time (which I have doubts about) and that adopting a different algorithm would improve things significantly. Ref: http://en.wikipedia.org/wiki/Amdahl's_law - Speedup in a Sequential Program

Jason Smith

-----Original Message----- From: Char@sun.com [mailto:Char@sun.com] On Behalf Of Charles Oliver Nutter Sent: Tuesday, December 04, 2007 12:00 PM To: us@groovy.codehaus.org Subject: Re: [groovy-user] Acceptable Placement of default: Within Switch?

Jochen Theodorou wrote:

if you do a micro benchmark of the performance between the to switch forms in Java (in bytecode) you will most probably not see a big difference between them. and they will probably behave just the same as a normal if-else cascade. Of course this is onlytrue on certain VMS, on others it is faster/slower, ut by such a small amount... its not worth it I say.

My understanding was that Groovy's switch is not a binary search, but a series of invoke/compare/jumps. That would be considerably slower than a direct jump table or a binary search. CS 101: a series of ifs will be O(n), a binary search will be O(log n), and table lookup O(1). table lookup is faster, so I believe it would be worth it.

- Charlie

--------------------------------------------------------------------- To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email