How Long Does it Take to Run "Hello World" in 5 Different Languages?
Join the DZone community and get the full member experience.
Join For FreeI was talking to Peter von der Ahé today about optimizing startup time. He asked me to guess how many classes the JVM had to load for a simple hello world application written in Java. He also asked me how long such a program would take to run. I didn't know the answers, so he quickly typed it out on a MacBook Pro.
Here's how to see how many classes are loaded:
java -verbose:class Hello
That results in 594 classes:
[Opened /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar] [Loaded java.lang.Object from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar] [Loaded java.io.Serializable from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar] [Loaded java.lang.Comparable from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar] ... [Loaded java.util.Collections$UnmodifiableMap from /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.ja
Java takes roughly 0.2 seconds to run hello world:
time java Hello Hello, World! real 0m0.212s user 0m0.221s sys 0m0.051s
Kind of interesting. I know that this is the world's stupidest benchmark, but I decided to write the same thing in Python. It takes 0.04 seconds.
Dart currently takes 0.02 seconds.
Ruby 1.8.7 takes 0.009 seconds.
C takes 0.006 seconds.
(Warning: bad joke coming...)
Of course, the real reason C is so fast is because it doesn't have any class.
As I said earlier, this is a totally stupid benchmark. Never pick a programming language based on how long it takes to run hello world. What happens if you have to write a program that says something other than hello world, such as "hej, verden"?Published at DZone with permission of Shannon Behrens, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments