Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: Passing a Method Name to a Method, Redux Date: Mon, 27 Jun 2011 18:03:42 -0700 Organization: A noiseless patient Spider Lines: 102 Message-ID: References: <1lu707p0cpr9vhrpv51d7hmst6bt1qdbcv@4ax.com> <0eqh071t45p7582aqk4qqdu59eplcmft93@4ax.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 28 Jun 2011 01:03:45 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="20GYBuezvHpp83lA3Rh62Q"; logging-data="20517"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ivbwpYgbgilM4O05TSeTTpJ8WscmN/to=" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 In-Reply-To: <0eqh071t45p7582aqk4qqdu59eplcmft93@4ax.com> Cancel-Lock: sha1:iE7DSaBEDIrLpuoPJJucXZo9wPc= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5717 On 6/27/2011 1:53 PM, Gene Wirchenko wrote: > > I am an experienced programmer, but I am not so experienced with > Java. I am trying to remedy the latter. Honestly, what you've done so far is pretty crazy. I figured you were a 2nd year student who got in over his head on a personal project, or a homework problem. No sane programmer would try to search for characters the way you are. If you want to tell us what your actual experience is, it might help. I'm guessing your experience isn't actually programming, maybe HTML and Flash or something. But I don't want to get into an argument here so if you don't want to tell us then it's ok to drop it. > On the confusion, I see that a number of people have > micro-optimised for my code. I am looking at a bigger picture. It's hard to give you a big picture. Well, a couple have tried. JavaCC or parboiled or similar compiler-compiler would help you the most. But besides that you've given us only a very micro example. We can't do anything else with the code other than micro-optimize. And on my system using a StringBuilder instead of '+' yields a 200% speed up. Times go from 22 seconds to around 6. I don't really call that micro. > > Of course not. The test code is just for dealing with > identifiers, and it is a simplified version to boot. Part of the problem is that you aren't really testing those three search routines. You're testing other things like string concatenation, because those are dominating the running time of your tests. I'd start over. Download an IDE like NetBeans. Start a new project with a single class with just the search routines (shown below). Use Tools -> Create Unit Tests. That will at least generate a saner framework for you to put your testing. It does need testing, and you can make a couple of tests do timing for you. I think it'll help you think about the problem more clearly too, things were kinda messy in there. class TimingTesting { 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; // Just these three methods and no more!!! static boolean SequentialSearch( char CurrChar ) { boolean fFound = false; for( int i = 0; i < IdentChars.length() && !fFound; i++ ) { fFound = IdentChars.charAt( i ) == CurrChar; } return fFound; } static boolean BinarySearch( char CurrChar ) { int xLow = 0; int xHigh = IdentChars.length() - 1; int xTry; boolean fFound = false; while( xLow <= xHigh ) { xTry = ( xLow + xHigh ) / 2; if( CurrChar == IdentChars.charAt( xTry ) ) { return true; } if( CurrChar < IdentChars.charAt( xTry ) ) { xHigh = xTry - 1; } else { xLow = xTry + 1; } } return false; } static boolean TreesetSearch( char CurrChar ) { return IdentCharsSet.contains( CurrChar ); } }