本文介绍了Groovy 2.0静态编译的性能如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到最近发布的Groovy 2.0包含了可选的静态编译以及其他一些额外的好处,比如可选的静态类型检查。在做了一些搜索之后,我还没有找到任何将Groovy的性能(与静态编译)和Java以及Scala进行比较的广泛基准。有谁知道任何这样的表现比较?我们可以假设它和Groovy ++在死前一样吗?如果性能是可比的话,那么Groovy会成为一个大型的性能关键型应用程序的可行替代方案吗?

基准测试(尽管很难看到发生了什么)



然而,从页面底部取得Groovy 1.8.2 Fib 源代码,并在groovy 2.0中运行它,可以获得:

  Groovy(静态三元):1623ms 
Groovy(静态if):1583ms
Groovy(实例三元):1744ms
Groovy(instance if):1694ms

放置 @ groovy.transform.CompileStatic 在脚本的顶部给你:

  Groovy(静态三元):819ms 
Groovy(static if):799ms
Groovy(实例三元):816ms
Groovy(if if):811ms

显然,这不是一个完整的基准(这只是测试它不包括热身或其他任何东西,而Groovy 2.0只出现一周,但它暗示了在这种情况下速度的提升......


I see that the recent release of Groovy 2.0 includes optional static compilation along with several other added benefits, like optional static type checking. After doing a bit of a search, I haven't been able to find any extensive benchmarks comparing Groovy's performance (with static compilation) to Java and perhaps Scala. Does anyone know of any such performance comparisons? Can we assume that it is the same as Groovy++ was before it died? If it's performance is comparable, would Groovy be a viable alternative for a large, performance-critical application?

解决方案

There are some benchmarks here (though it's hard to see what's going on)

However, taking the Groovy 1.8.2 Fib source code from the bottom of the page, and running it in groovy 2.0 gives you:

Groovy(static ternary): 1623ms
Groovy(static if): 1583ms
Groovy(instance ternary): 1744ms
Groovy(instance if): 1694ms

Putting @groovy.transform.CompileStatic at the top of the script gives you:

Groovy(static ternary): 819ms
Groovy(static if): 799ms
Groovy(instance ternary): 816ms
Groovy(instance if): 811ms

Obviously, this is not a complete benchmark (it's only testing one thing), it doesn't include warmup or anything, and Groovy 2.0 has only been out a week, however it does hint towards a good speed improvement in this situation...

这篇关于Groovy 2.0静态编译的性能如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 19:14