Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.lang.java.programmer > #5717

Re: Passing a Method Name to a Method, Redux

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 <iub99g$k15$1@dont-email.me> (permalink)
References <fpg7079ca2dtgipdphr8rm234kgmkd1t3l@4ax.com> <iu0pbg$26n$1@dont-email.me> <1lu707p0cpr9vhrpv51d7hmst6bt1qdbcv@4ax.com> <iu129n$d0q$1@dont-email.me> <aim907llv5vnl8910jb7bim7htjm4a4ben@4ax.com> <iu2o12$li3$1@dont-email.me> <mguf07h7vl3aju927nfj67h4gh6naullgu@4ax.com> <iu9889$vbj$1@dont-email.me> <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

Show key headers only | View raw


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<Character> IdentCharsSet
         = new TreeSet<Character>();
     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 );
     }

}

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-23 16:03 -0700
  Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-23 16:26 -0700
    Re: Passing a Method Name to a Method, Redux blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-06-27 21:41 +0000
  Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-23 17:24 -0700
    Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-23 19:46 -0700
      Re: Passing a Method Name to a Method, Redux blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-04 03:26 +0000
        Re: Passing a Method Name to a Method, Redux lewbloch <lewbloch@gmail.com> - 2011-07-04 03:41 -0700
          Re: Passing a Method Name to a Method, Redux blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-05 19:07 +0000
  Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-23 17:34 -0700
    Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-23 19:42 -0700
  Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-23 18:30 -0700
    Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-23 19:48 -0700
      Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-23 21:02 -0700
        Re: Passing a Method Name to a Method, Redux lewbloch <lewbloch@gmail.com> - 2011-06-24 08:38 -0700
          Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-24 09:04 -0700
            Re: Passing a Method Name to a Method, Redux Lew <noone@lewscanon.com> - 2011-06-26 13:43 -0400
              Re: Passing a Method Name to a Method, Redux Lew <noone@lewscanon.com> - 2011-06-26 14:31 -0400
        Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-24 11:45 -0700
          Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-24 12:19 -0700
            Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-26 20:39 -0700
              Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-26 23:33 -0700
                Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-27 13:53 -0700
                Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-27 18:03 -0700
                Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-28 11:41 -0700
        Re: Passing a Method Name to a Method, Redux blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-06-24 19:19 +0000
  Re: Passing a Method Name to a Method, Redux Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-06-23 19:36 -0700
    Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-24 11:50 -0700
      Re: Passing a Method Name to a Method, Redux Jeff Higgins <jeff@invalid.invalid> - 2011-06-24 17:25 -0400
        Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-26 20:42 -0700
          Re: Passing a Method Name to a Method, Redux markspace <-@.> - 2011-06-26 23:27 -0700
          Re: Passing a Method Name to a Method, Redux Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-06-27 03:04 -0400
            Re: Passing a Method Name to a Method, Redux Gene Wirchenko <genew@ocis.net> - 2011-06-27 13:12 -0700
              Re: Passing a Method Name to a Method, Redux Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-06-27 13:36 -0700
      Re: Passing a Method Name to a Method, Redux Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-06-24 15:50 -0700

csiph-web