Over a million developers have joined DZone.
Platinum Partner

How Long Does it Take to Run "Hello World" in 5 Different Languages?

· Performance Zone

The Performance Zone is brought to you in partnership with AppDynamics. Discover five of the top performance metrics to capture to assess the health of your enterprise Java application.

I 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"?

The Performance Zone is brought to you in partnership with AppDynamics.  Learn the essentials of APM and how to implement best practices of application performance, better understand what it means to capture, analyze, and react to performance problems as they arise, and more specifically with .NET applications. 

Topics:

Published at DZone with permission of Shannon Behrens , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}