Tuesday, July 10, 2012

Java vs Groovy2.0 vs Scala Simple Performance Test

Since Groovy2.0 is out, I want to re-test the performance difference between Java, Groovy2.0 and Scala. The previous tests: Part 1 and Part 2

The machine and the code are the same as the previous tests. The only thing change is that I am using groovy2.0. To make it the results more clear, I am only including the results for f(30) and f(50):

n implementation result Java Groovy2 Groovy2 @CompileStatic Scala
30 for-loop 832040 0 (ms) 0 (ms) 1 (ms) 0 (ms)
30 recursive 832040 19 (ms) 66 (ms) 20 (ms) 20 (ms)
50 for-loop 12586269025 0 (ms) 0 (ms) 0 (ms) 0 (ms)
50 recursive 12586269025 182462 (ms) 356920 (ms) 176468 (ms) 180898 (ms)


I split the Groovy test to two. One with the new annotation @CompileStatic (I put it in the class level) and one without. The one without is suppose to use the JDK7 new feature invokeDynamic which should give some performance gain but unfortunately JDK7 is not supported in Mac Snow Leopard. @CompileStatic is a new feature that give performance gain to groovy code with type safety check where dynamic features are not required. More information here.

The results show that the big performance gain by adding the @CompileStatic which is making Groovy up to par with Java and Scala. The common ways for Groovy developers to solve performance's problem is to write that piece of code in Java. Now with this new @CompileStatic, everything can be just in Groovy. And the ideal case is that if the JDK7 invokeDynamic gives Groovy2 the same performance as Java, then the @CompileStatic is not needed at all (if you want type safe, you can just use another new annotation @TypeChecked).

10 comments:

  1. I don't think Groovy, although using @CompileStatic, is faster than Java...

    ReplyDelete
  2. Thanks for sharing such informative article on Loadrunner Automation testing tool. This load testing tool will provide most precise information about the quality of software. Loadrunner training in Chennai

    ReplyDelete
  3. An obligation of appreciation is all Hadoop Training in Chennai together for sharing such instructive article on Loadrunner Automation testing instrument. Hadoop Training in Chennai This stack testing mechanical Oracle Training in Chennai assembly will give most correct information about the way of programming.

    ReplyDelete
  4. Cloud computing is storing and accessing the large data sets over the internet instead of your PC computer. So that you can manage the data and program anywhere through the internet.
    Regards..
    Cloud Computing Training Centers in Chennai

    ReplyDelete
  5. Your blog is really useful for me. Thanks for sharing this informative blog. If anyone wants to get real time Oracle Training Chennai reach FITA located at Chennai. They give professional and job oriented training for all students.

    ReplyDelete
  6. Thanks for sharing this information. Java is one of the popular object oriented programming language used for many of the multinational corporation. So learning Java Training in Chennai is really helpful to make a bright future.

    ReplyDelete
  7. Excellent post. Android is an open source operating system used for tablet computers and smartphones. If your are interested to develop creative mobile applications then you must learn about android OS. Its helpful for you.

    Regards..
    Android Training Institutes in Chennai

    ReplyDelete
  8. Nice information. Salesforce is a most powerful CRM tool used for manage all customers including potential customers. Salesforce Training in Chennai offering this course with experienced professionals.

    ReplyDelete
  9. Really nice post. Unix is a multiuser and multi tasking operating system at the same time. Unix Training in Chennai offering real time Unix course at reasonable cost.

    ReplyDelete
  10. Really awesome blog. Software testing is a method of executing the application or program with the intent of searching the software errors. Software Testing Training in Chennai offering this course at reasonable cost.


    ReplyDelete