Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


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

Re: Passing a Method Name to a Method, Redux

From Gene Wirchenko <genew@ocis.net>
Newsgroups comp.lang.java.programmer
Subject Re: Passing a Method Name to a Method, Redux
Date 2011-06-26 20:39 -0700
Organization A noiseless patient Spider
Message-ID <mguf07h7vl3aju927nfj67h4gh6naullgu@4ax.com> (permalink)
References (1 earlier) <iu0pbg$26n$1@dont-email.me> <1lu707p0cpr9vhrpv51d7hmst6bt1qdbcv@4ax.com> <iu129n$d0q$1@dont-email.me> <aim907llv5vnl8910jb7bim7htjm4a4ben@4ax.com> <iu2o12$li3$1@dont-email.me>

Show all headers | View raw


On Fri, 24 Jun 2011 12:19:58 -0700, markspace <-@.> wrote:

>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, 

     You are misunderstanding.  The test code that I am referring to
is proof-of-concept code to test ideas, *not* my test cases.

>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.

     I have heard about the String/StringBuilder dichotomy.  I will be
addressing it.

>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 ) );

     But I do not want to do that.  I am writing a preprocessor to
process files like:
***** Start of Test File *****
* testin.dat
* Test Input File for Preprocessor
* Last Modification: 2011-06-16
*
* This is VFP code.

$idchars ABC 1 2 A
$idchars
$quotes "" '' [] ~
$rem testin2.dat contains the definitions of STARTTEXT and ENDTEXT.
$rem
$include "testin2.dat"
$include testin2.dat
$include ~Atestin.datA
$include "testin2.dat"X
$include ~Atestin.datAX

$define FROM 1
$define TO 10
   set talk off

   ? "STARTTEXT"

   for i=FROM to TO
      ? i
      endfor

   ? ENDTEXT

   return
$undef FROM
$undef TO
***** End of Test File *****

Sincerely,

Gene Wirchenko

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