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


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

Re: Passing a Method Name to a Method, Redux

From markspace <-@.>
Newsgroups comp.lang.java.programmer
Subject Re: Passing a Method Name to a Method, Redux
Date 2011-06-24 12:19 -0700
Organization A noiseless patient Spider
Message-ID <iu2o12$li3$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>

Show all headers | View raw


On 6/24/2011 11:45 AM, Gene Wirchenko wrote:

>       No.  I expect that I will be using the resulting preprocessor for
> years.  The test code will be tossed shortly.

You have a couple of problems with your code, one organizational and the 
other understanding the effeciencies.

The organizational one relates to the idea that you'll just toss your 
tests away.  Don't ever do that!  The test code is part of the project, 
and should remain with it.  Test code is also put under code control, 
and managed along with the projects. It's important because every time 
you want to change your parser, you'll need to re-run the tests to make 
sure everything is working.

Are you using an IDE?  Most will auto generate a test framework for you. 
  It's very handy and you should be doing this regardless how you write 
code.  The IDE just makes it very handy.

>       No.  I am just after the timing.

The other thing, efficiency, I'll show you right now.  The 
organizational stuff is actually probably a bigger deal, but I think 
you'll be happy to see how to make code faster.

This line here is the biggest offender.

>        cIdent += CurrChar;

This is super inefficient inside a loop.  To do this, the system has to 
create a new string with one extra character, and then toss away the old 
string.  Making a new object and tossing an old one is bound to slow you 
down.

final public void parse() {
         StringBuilder sb1 = new StringBuilder( 255 );
         for( int xScan = 0; xScan < 
TimingTesting.cParseString.length(); xScan++ ) {
             char c = TimingTesting.cParseString.charAt( xScan );
             if( find( c ) ) {
                 sb1.append( c );
             }
         }
         String ... = sb1.toString()

Here's my adaptation of your loop.  Notice I make a StringBuilder once, 
outside the loop, and call append() inside the loop, which is much much 
faster.  Then I call toString once outside the loop again, so I only 
create a new String once, not each time inside the loop.  Try to 
refactor your code to do this, it will make it much faster.


One last thing for now:  on splitting a string into tokens, look at this:

    String[] tok = TimingTesting.cParseString.split( "[^a-zA-Z0-9]+" );
    System.out.println( Arrays.toString( tok ) );

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