性能和Java互操作性:Clojure与Scala [英] On Performance and Java Interoperability: Clojure vs. Scala

查看:99
本文介绍了性能和Java互操作性:Clojure与Scala的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经读过Clojure和Scala的各种帐户,虽然我意识到两者都有自己的位置。有几个注意事项,我没有获得关于比较Clojure和Scala的完整解释:

I have already read various accounts of Clojure vs. Scala and while I realize that both have their place. There are a few considerations that I haven't acquired a complete explanation on when it comes to comparing both Clojure with Scala:

1。)这两种语言中的哪一种更快?我意识到,这将从一个语言功能到另一个,但对性能的一般评估将有所帮助。例如:我知道Python字典真的很快。但作为一个整体,它是一种比Java慢得多的语言。我不想和Clojure一起去解决这个问题。

1.) Which of the two languages is generally faster? I realize that this will vary from one language feature to another but an general assessment of performance would be helpful. For example: I know that Python dictionaries are really fast. But as a whole, it is a much slower language than Java. I don't want to go with Clojure and run into this problem down the road.

2。)与Java的互操作性如何?到目前为止,我所阅读的是Scala有一些原生的集合类型,使它有点笨拙,与大型Java代码库集成,而Clojure遵循一个简单的Iterable / Iterator中心的方式与Java类进行交互。有任何更多的想法/细节吗?

2.) How is interoperability with Java? All I have read so far is that Scala has native collections types that make it a bit clumsy to integrate with a large Java code-base, whereas Clojure follows a simple Iterable/Iterator-centric way to inter-operate with Java classes. Any more thoughts/details on this?

最终,如果它是一个足够接近clojure和scala之间的绘制,我可以尝试他们两个。关于Clojure的一件事是语言看起来很简单。 但是再次,Scala有一个非常灵活的类型系统。但是,我知道Scala是快速(基于多个个人帐户)。所以,如果Clojure显着更慢:我想知道更快,而不是后来。

Ultimately, if it is a close enough draw between clojure and scala, I might try them both. One thing about Clojure is the language seems very simple. But then again, Scala has a very flexible type system. But, I know that Scala is fast (based on multiple personal accounts). So, if Clojure is significantly slower: I'd like to know sooner rather than later.

推荐答案

足够快为你。当比较Python和Java,似乎有点不合理的责怪语言的速度差异。 Java是编译JIT(除了在移动设备*),而Python是解释。只是因为两者使用字节码并不意味着实现将甚至具有远程可比性能。但是Scala和Clojure都是JVM语言,所以它们应该具有类似的性能。

I think either language will be fast enough for you. When comparing Python and Java, it seems a bit unreasonable to blame the language for the speed difference. Java is compiled JIT (except on mobile devices*) whereas Python is interpreted. Just because both use a bytecode does not mean the implementations will have even remotely comparable performance. But both Scala and Clojure are JVM languages so they should have similar performance.

Scala与Clojure相比有一些实现优势,我希望性能稍高一些。虽然Scala的静态类型通常会转化为速度优于Clojure的鸭式类型,Clojure 支持类型提示,可以大大加快代码。可能,普通的Scala比普通的Clojure更快,但你只需要优化瓶颈。大多数程序的运行时间是由少量的实际代码生成的。

Scala has a few implementation advantages over Clojure and I would expect somewhat higher performance. Although Scala's static typing would normally translate into a speed advantage over Clojure's duck typing, Clojure does support type hinting which can speed up code considerably. Possibly, ordinary Scala is faster than ordinary Clojure, but you only need to optimize the bottlenecks. Most of a program's run time is generated by a small amount of the actual code.

关于interop w / Java,Scala更接近Java,但我敢肯定两种语言互操作性好。在编程Clojure 中,Stuart Halloway写道:你可以访问从Java代码可以访问的任何内容。。

Regarding interop w/ Java, Scala is closer to Java but I'm sure both languages interoperate well. In Programming Clojure Stuart Halloway writes: "[you can access] anything you could reach from Java code.".

由于Scala作者Martin Odersky 写了Sun的Java编译器,我认为没有球被丢弃在Scala一侧。 : - )

And since Scala author Martin Odersky wrote Sun's Java compiler, I kinda think no balls have been dropped on the Scala side, either. :-)

你会很难选择两种更好的语言,虽然我也喜欢Ruby。你为什么担心要试试哪一个?为什么不试试两个? Scala更有可能是下一个Java,但很难想象Lisp在50多年没有这样做之后终将起飞。但是很清楚,Lisp是在它自己独特的抽象层次上,而Clojure是相当简单的,所以Scala + Clojure不会比只是(相当复杂的)Scala难得多,我相信你会很高兴你做它。

You would be hard-pressed to pick two better languages, though I like Ruby also. Why are you worried about which one to try? Why not try them both? Scala is more likely to be "the next Java", while it's hard to imagine that Lisp will finally take off after not doing so for over 50 years. But it's clear that Lisp is on its own unique level of abstraction, and Clojure is fairly simple, so Scala + Clojure won't be that much harder than just (the rather complex) Scala and I'm sure you will be glad you did it.

因此,他们互操作...

And for that matter they interoperate...

* dalvik(android的JVM) 2.2版本在2010年

* dalvik (android's JVM) got a JIT compiler in 2.2 version in 2010

这篇关于性能和Java互操作性:Clojure与Scala的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆