Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: blmblm@myrealbox.com Newsgroups: comp.lang.java.programmer Subject: Re: Passing a Method Name to a Method, Redux Date: 24 Jun 2011 19:19:57 GMT Organization: None Lines: 201 Message-ID: <96k6atFt60U2@mid.individual.net> References: <1lu707p0cpr9vhrpv51d7hmst6bt1qdbcv@4ax.com> X-Trace: individual.net KVT2fJUk43Rl1SxS0kzTzQEv5m121PFt2mJSPdrm8hULRjMS87 X-Orig-Path: not-for-mail Cancel-Lock: sha1:UlAMwdUdyxm8TrHbdYX3c6HXd7o= X-Newsreader: trn 4.0-test76 (Apr 2, 2001) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5654 In article , markspace <-@.> wrote: > On 6/23/2011 7:48 PM, Gene Wirchenko wrote: > > On Thu, 23 Jun 2011 18:30:21 -0700, markspace<-@.> wrote: [ snip ] > BTW I refactored your test that you were copy-and-pasting around into > one method. Using techniques I mentioned in my first post to you on > this subject. > > private static void time( TestCase r ) { > long StartTime = System.nanoTime(); > for( int i = 1; i <= nRepetitions; i++ ) { > r.parse(); > } > long EndTime = System.nanoTime(); > long Duration = EndTime - StartTime; > System.out.println( " Duration=" + (Duration/1e9) ); > } Gene -- Below is my revision, along similar lines to what markspace suggests above but a complete program program based on your code. I tried not to make gratuitous additional changes, but I admit that I did move the declaration of the loop counter into the "for" construct because, well, *one* gratuitous change to make the program look less Java-unidiomatic? (Also I admit I ran the whole program through vim's "reindent", but that should change only whitespace.) Non-whitespace changes marked "// (blmblm)". import java.util.*; public class TimingTesting2 { // (blmblm) added interface Searcher { boolean search(char CurrChar); } static String cParseString= "//identifier//IDENTIFIER//a_b_c abc1234b5%$__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