Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Passing a Method Name to a Method, Redux

Reply
Thread Tools

Passing a Method Name to a Method, Redux

 
 
Lew
Guest
Posts: n/a
 
      06-26-2011
On 06/26/2011 01:43 PM, Lew wrote:
> On 06/24/2011 12:04 PM, markspace wrote:
>> On 6/24/2011 8:38 AM, lewbloch wrote:
>>
>>> You'll want to run each loop a bunch of times (10,000? 100,000?>=
>>> 1M?) before starting the timing loop in order to cancel the effects of
>>> HotSpot warmup.

>>
>>
>> I was hoping that the -server flag would obviate most or all warm-up (this is
>> from another post in this tread):
>>
>> C:\Users\Brenden\Dev\Test2\src>java -server test.CallingTest
>>
>> No?

>
> No. How could it?


"-server

"JVMs based on Sun's Hotspot technology initially compile class methods with a
low optimization level. These JVMs use a simple complier [sic] and an
optimizing JIT compiler. Normally the simple JIT compiler is used. However you
can use this option to make the optimizing compiler the one that is used. This
change will significantly increases [sic] the performance of the server but
the server takes longer to warm up when the optimizing compiler is used."

<http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/tprf_tunejvm.html>

--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedi.../c/cf/Friz.jpg
 
Reply With Quote
 
 
 
 
Gene Wirchenko
Guest
Posts: n/a
 
      06-27-2011
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
 
Reply With Quote
 
 
 
 
Gene Wirchenko
Guest
Posts: n/a
 
      06-27-2011
On Fri, 24 Jun 2011 17:25:01 -0400, Jeff Higgins
<(E-Mail Removed)> wrote:

>On 06/24/2011 02:50 PM, Gene Wirchenko wrote:
>> On Thu, 23 Jun 2011 19:36:53 -0700, Joshua Cranmer


[snip]

>> I am writing a *simple* parser. It is not for grovelling over
>> Java code. It is for a preprocessor for SQL Server for better code
>> management. I mean for it to be fairly language-agnostic.
>>

>What means simple? JavaCC is the parser generator that I'm most familiar
>with. <http://javacc.java.net/>


There are preprocessor commands. For them, the first character
of the line is "$". All of the other lines are text to be processed.
There is one level of string substitution.

Think simple version of the C preprocessor.

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      06-27-2011
On 6/26/2011 8:42 PM, Gene Wirchenko wrote:

> On Fri, 24 Jun 2011 17:25:01 -0400, Jeff Higgins
>> What means simple? JavaCC is the parser generator that I'm most familiar
>> with.<http://javacc.java.net/>


> There are preprocessor commands. For them, the first character
> of the line is "$". All of the other lines are text to be processed.
> There is one level of string substitution.



A parser generator makes parsers for you. You give it a syntax (like
"starts with $") and it makes the parser. Generally very efficient as
it will do optimizations in the code that are hard to find.

 
Reply With Quote
 
markspace
Guest
Posts: n/a
 
      06-27-2011
On 6/26/2011 8:39 PM, Gene Wirchenko wrote:

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


I don't see what you are doing then. Is the code you showed us not your
"test/proof of concept?"

First, a proof of concept is a little silly for a parser. Of course
it's feasible. And then you are running timing test on it. Shouldn't
you be doing time tests on something you intend to throw away? Profile
the real code!

You seem to be making a lot of extra work for yourself, or at least
confusing the heck out of us.


> But I do not want to do that. I am writing a preprocessor to
> process files like:


You should be using input like what you showed to test then. The test
code you showed us won't parse this correctly.
 
Reply With Quote
 
Joshua Cranmer
Guest
Posts: n/a
 
      06-27-2011
On 06/26/2011 11:42 PM, Gene Wirchenko wrote:
> Think simple version of the C preprocessor.


Then why not use the C preprocessor?

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      06-27-2011
markspace <-@.> writes:
>A parser generator makes parsers for you. You give it a syntax (like
>"starts with $") and it makes the parser. Generally very efficient as
>it will do optimizations in the code that are hard to find.


Seems as if writing a grammar is more difficult for some
people that to write a parser, possibly, because it requires
abstraction.

The previous poster claimed, however, that his grammar (at
least: the set of characters allowed in an identifier) would
change at run time. This would mean that there is no static
grammar (at least for the identifier symbol).

 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      06-27-2011
Joshua Cranmer <(E-Mail Removed)> writes:
>On 06/26/2011 11:42 PM, Gene Wirchenko wrote:
>>Think simple version of the C preprocessor.

>Then why not use the C preprocessor?


The previous poster claimed that the set of characters that
can be used within an identifier is supposed to change
during the execution of his parser. This is not possible
with the C preprocessor whose set of identifier characters
is { "_", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9" }.

 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      06-27-2011
On Mon, 27 Jun 2011 03:04:11 -0400, Joshua Cranmer
<(E-Mail Removed)> wrote:

>On 06/26/2011 11:42 PM, Gene Wirchenko wrote:
>> Think simple version of the C preprocessor.

>
>Then why not use the C preprocessor?


I could not find one that would run standalone on my system.

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Joshua Cranmer
Guest
Posts: n/a
 
      06-27-2011
On 6/27/2011 1:12 PM, Gene Wirchenko wrote:
> On Mon, 27 Jun 2011 03:04:11 -0400, Joshua Cranmer
> <(E-Mail Removed)> wrote:
>
>> On 06/26/2011 11:42 PM, Gene Wirchenko wrote:
>>> Think simple version of the C preprocessor.

>>
>> Then why not use the C preprocessor?

>
> I could not find one that would run standalone on my system.


Then if I may make a recommendation, try using mcpp.
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing a Method Name to a Method Gene Wirchenko Java 33 06-25-2011 07:26 PM
Passing a method(reference) to an other method and calling themethod. Erik Java 11 03-29-2008 07:26 AM
Passing method name to method? Arfon Smith Ruby 3 09-28-2007 03:38 PM
Passing math method to another method? Neutek Ruby 11 01-18-2007 09:23 AM
Re: Urgent! how to get object name, method name and attribute name based on the strings? ding feng C++ 2 06-25-2003 01:18 PM



Advertisments