Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Gene Wirchenko Newsgroups: comp.lang.java.programmer Subject: Passing a Method Name to a Method, Redux Date: Thu, 23 Jun 2011 16:03:34 -0700 Organization: A noiseless patient Spider Lines: 256 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: mx04.eternal-september.org; posting-host="7Qrvczazr82YckO5XW8Vtw"; logging-data="15232"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TPUl54lz2ln4gnZwP+cR1suCl3I1mWeM=" X-Newsreader: Forte Agent 4.2/32.1118 Cancel-Lock: sha1:wYlRWfcdGHAO5ck5sZ0Pb2QGZcg= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5610 Dear Java'ers: I have completed my benchmarking. The code is below. Note that the difference in the bodies between ParseSequentialSearch(), ParseBinarySearch(), and ParseTreesetSearch() is but one line. I really would have preferred not having to duplicate the code. Oddly, the timings have a LOT of noise in them. In some runs, a sequential search has out-performed a binary search. Occasionally, a sequential search has beaten both a binary search and a Treeset search. The times for sequential searching are only a bit worse than for binary searching. Treeset searching is about 20% faster. Any explanations? I had to kludge this: cIdent=""+CurrChar; cIdent is a String, CurrChar is a char. cIdent=CurrChar; does not compile. So how would you have written this benchmark? ***** Start of Code ***** // TimingTesting // Timing Testing of Character Searching // Last Modification: 2011-06-23 import java.util.*; class TimingTesting { static String cParseString= "//identifier//IDENTIFIER//a_b_c abc123 4b5%$__dbl;one;two;three;END"; static String IdentChars= "0123456789"+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+ "_"+ "abcdefghijklmnopqrstuvwxyz"; // sorted order! static SortedSet IdentCharsSet=new TreeSet(); static int nRepetitions=1000000; static boolean SequentialSearch ( char CurrChar ) { boolean fFound=false; for (int i=0; i