Re: Resulting class performance
Scott Vachalek <[email protected]>
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <[email protected]> |
Look up "Java vs. C++ performance" to see all the problems that can occur with this sort of micro-benchmark. It could all come down to differences in measurement (whether both VMs are running in the same mode, whether startup time is counted, etc. etc.) But off the top of my head, I would try replacing that ldc with an iconst. I'd be surprised if the JIT doesn't produce equivalent code in both cases but that seems to be the most prominent difference. On Fri, May 7, 2010 at 12:40 PM, Jeremy Cowgar <[email protected]> wrote: > I am writing a language called Josl (http://www.josl.org). Currently it is > interpreted by it's own VM. I am finding that I spend as much time on the VM > as I do with the language and this week I have been researching the JVM and > targeting it. This will provide JIT compilation but more importantly all the > great libraries that come with Java and are available. Today I began writing > a compiler in Java for the Josl language using ASM to generate the code. I > have a test compiler working for a bare bones version of Josl. It does a > poor job of parsing the code, does string compares for key words, etc... but > it works. I then setup a benchmark (benchmarking too early? :-D). > > Anyway, I am concerned that I am not understanding something correctly. > Here is my benchmark program. I've used it early on to just see what the raw > VM loop speed is. i.e. do as minimal amount of work possible. Josl is a > stack based language, BTW and it's entry word is "main", just like Java's. > > main 0 300,000,000 times 1+ next > > So, that starts at 0 and adds 1 each time through 300 million times. In > Josl on my machine it takes 2.561 seconds. In my resulting .class file, It > takes 3.009 seconds. I was expecting a huge performance increase. > > I placed all my Josl-java code on github: > http://github.com/jcowgar/josl-jvm ... now, bear in mind, I just wanted to > quickly get to the part of making JVM byte code, pay no attention to the > total lack of proper word lookups, the poor parser, etc... All that will > completely change. > > Now, I also made this program in Java, it's source is: > > public class LoopTest { > public static void main(String args[]) { > int i = 0; > int current = 0; > int finish = 300000000; > > while (current < finish) { > i = i+ 1; > current++; > } > } > } > > I tried to do it just as I did in Josl, i.e. I have a loop counter I call > current, I also have a finish counter. Each time through I check to see if > current < finish, I increment current and I do whatever else is contained in > the body of the loop, in this case adding 1 to a variable each time. > > The above LoopTest runs in 0.259 seconds. That's the kind of performance I > was expecting with my .class files. I have used javap -c on both the > LoopTest class and my class, they do not loop a whole lot different. Does > anyone know what the performance difference could be caused by? > > LoopTest dump: > > public class LoopTest extends java.lang.Object{ > public LoopTest(); > Code: > 0: aload_0 > 1: invokespecial #1; //Method java/lang/Object."<init>":()V > 4: return > > public static void main(java.lang.String[]); > Code: > 0: iconst_0 > 1: istore_1 > 2: iconst_0 > 3: istore_2 > 4: ldc #2; //int 300000000 > 6: istore_3 > 7: iload_2 > 8: iload_3 > 9: if_icmpge 22 > 12: iload_1 > 13: iconst_1 > 14: iadd > 15: istore_1 > 16: iinc 2, 1 > 19: goto 7 > 22: return > > } > > JoslProgram dump: > > public class JoslProgram extends java.lang.Object{ > public JoslProgram(); > Code: > 0: aload_0 > 1: invokespecial #8; //Method java/lang/Object."<init>":()V > 4: return > > public static void main(java.lang.String[]); > Code: > 0: ldc #11; //int 0 > 2: ldc #12; //int 300000000 > 4: istore_1 > 5: iconst_0 > 6: istore_0 > 7: iload_1 > 8: iload_0 > 9: if_icmple 21 > 12: ldc #13; //int 1 > 14: iadd > 15: iinc 0, 1 > 18: goto 7 > 21: return > > } > > > > -- > You receive this message as a subscriber of the [email protected] mailing list. > To unsubscribe: mailto:[email protected] > For general help: mailto:[email protected]?subject=help > OW2 mailing lists service home page: http://www.ow2.org/wws > >
message-footer.txt
(text/plain, 238 B)
-- You receive this message as a subscriber of the [email protected] mailing list. To unsubscribe: mailto:[email protected] For general help: mailto:[email protected]?subject=help OW2 mailing lists service home page: http://www.ow2.org/wws