JVM optimization



Hi,
two functions test1 and test2 does the same thing but test2 performs
nearly 20 times better than test1. JVM is unable to optimize the code
in test1. is there a way to tell the java virtual machine to do this
kind of optimization at compile time or runtime?
NOTE : we are using Log4J and java version "1.4.2_02"
private static final Logger log = Logger.getLogger(DebugTest.class);

--------------------------------------------------------------------------

public void test1() {
for (int i = 0; i < 10000000;i++) {
String s ="test"+i;
if(log.isDebugEnabled()) {
log.debug(s);
}
}
}

public void test2() {
for (int i = 0; i < 10000000;i++) {
if(log.isDebugEnabled()) {
String s ="test"+i;
log.debug(s);
}
}
}
--------------------------------------------------------------------------

.



Relevant Pages

  • Re: Junit newbie
    ... > time in junit versus my actual class. ... > iteratively test de/compressing a single byte array with the values ranging ... As to what if test2 requires test1 to pass? ...
    (comp.lang.java.help)
  • Re: semBCreate, SEM_Q_FIFO
    ... The problem is definitely one of context switching and scheduling. ... The two tasks (test1 and test2) were at the same priority. ... next iterations of task1 will be so fast that task1 will finish ...
    (comp.os.vxworks)
  • Re: Changing the local admin password base on the computers OU
    ... You can put the common code of the two IF-bodies in front of them, ... 'Change the local admin pwd for OU TEST1 ... 'Change the local admin pwd for OU TEST2 ... I do not know what it means to test for a computers membership in ...
    (microsoft.public.scripting.vbscript)
  • Re: Validation Options with option List
    ... If you are talking about actual tests (e.g. test1 has several questions, ... test2 has several questions and so on) you can do this. ... > Could you not just add a simple IF test in an adjoining cell ... >> i have set up an validation list option in Excel so i can choose what ...
    (microsoft.public.excel.misc)
  • data comprised of regexs (while loop weirdness)
    ... why do I only see a yes when passing the last data entry (test3) as ... <end code snipet> ...
    (comp.lang.perl.misc)