哪个更快,Clojure或ClojureScript(和为什么)? [英] Which is faster, Clojure or ClojureScript (and why)?

查看:170
本文介绍了哪个更快,Clojure或ClojureScript(和为什么)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我不得不猜测,我很肯定答案是Clojure,但我不知道为什么。逻辑上(对我来说)似乎ClojureScript应该更快:

If I had to guess, I'm pretty sure the answer is Clojure, but I'm not sure why. Logically (to me) it seems like ClojureScript should be faster:

两者都是动态,但ClojureScript

Both are "dynamic", but ClojureScript


  • 编译为在V8上运行的JavaScript

  • V8引擎可以说是最快的动态语言引擎。

  • V8用C写的

,而Clojure:


  • 也是动态的

  • 在JVM中运行,它没有内置的动态支持,所以我认为JVM必须做任何V8也做,以启用动态支持

  • Java比C慢

那么Clojure如何比ClojureScript更快? 动态是什么意思,说JavaScript是动态的,而Clojure是动态的?

So how could Clojure be faster than ClojureScript? Does "dynamic" mean something different when saying JavaScript is dynamic and Clojure is dynamic? What am I not seeing?

(当然,如果ClojureScript 确实更快,那么上述推理是否正确?)

(Of course if ClojureScript is indeed faster, then is the above reasoning correct?)

我想,Clojure编译为....至少是问题的一部分。我知道JVM部分不能只是一个简单的解释器(否则ClojureScript会更快),但Clojure不能编译到正常的字节码,因为在JVM没有动态。那么ClojureScript如何被编译/执行,Clojure是如何被编译/优化以及如何编译/执行纯Java,以及每个

I guess, what does Clojure compile to....is at least part of the question. I know the JVM part can't just be a plain interpreter (otherwise ClojureScript would be faster), but Clojure can't compile to regular bytecode, as there's no "dynamic" in the JVM. So what's the difference between how ClojureScript is compiled/executed and how Clojure is compiled/excecuted and how plain Java is compiled/executed, and the performance differences implied in each?

推荐答案

这个问题很难准确回答,没有引用一个特定的基准任务(甚至特定版本的Clojure或ClojureScript)。

This question is hard to answer precisely, without reference to a specific benchmark task (or even specific versions of Clojure or ClojureScript).

说了,在大多数情况下,我期望Clojure有点快。原因:

Having said that, in most situation I would expect Clojure to be somewhat faster. Reasons:


  • Clojure 通常会编译为 static t实际上在运行时执行任何动态查找。这是非常重要的:高性能代码通常产生与静态类型的Java非常相似的字节码。这个问题似乎假设动态语言必须在运行时进行动态方法查找:这并不总是这样(通常不是在Clojure中)

  • JVM JIT是非常好的工程,我相信它目前仍然比JavaScript JIT更好一点,尽管V8是多么好。

  • 如果你需要并发或需要利用多个核心那么显然没有竞争,因为JavaScript是单线程的.....

  • Clojure编译器比ClojureScript更成熟,并且近年来进行了大量的性能调优工作(包括原始支持,协议等)

  • Clojure usually compiles down to static code, so it doesn't actually do any dynamic lookups at runtime. This is quite important: high performance code often produces bytecode that is very similar to statically typed Java. The question appears to be making the false assumption that a dynamic language has to do dynamic method lookups at runtime: this is not always the case (and usually isn't in Clojure)
  • The JVM JIT is very well engineered, and I believe it is currently still a bit better than the JavaScript JITs, despite how good V8 is.
  • If you need concurrency or need to take advantage of multiple cores then clearly there is no contest since JavaScript is single-threaded.....
  • The Clojure compiler is more mature than ClojureScript, and has had quite a lot of performance tuning work in recent years (including things like primitive support, protocols etc.)

当然,可以用任何语言编写快速或慢速代码。

Of course, it is possible to write fast or slow code in any language. This will make more of a difference than the fundamental difference between the language implementations.

更基本的是,你在Clojure和ClojureScript之间的选择不应该是在任何情况下的性能。两者都提供了令人信服的生产力优势。主要决定因素应为:

And more fundamentally, your choice between Clojure and ClojureScript shouldn't be about performance in any case. Both offer compelling productivity advantages. The main deciding factor should be:


  • 如果您想在网路上执行,请使用ClojureScript

  • 如果要在JVM环境中的服务器上运行,请使用Clojure

这篇关于哪个更快,Clojure或ClojureScript(和为什么)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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