Comparing clojure and node.js for speed
swizec.com
swizec.com
I don't know node, so I don't know if he's making similar mistakes on that side.
Startup time for the jvm seemed fair, because node has to start up as well. This should count into the overall time imho.
I may play with the type hints tonight if I get time. It shouldn't make it slower.
We are finding node to be quite nice, though, for our real-time web app (which includes chat communication, and game like features). But we don't have any long-running calculations to do. I suspect that if we did we'd have them run in a separate server process... maybe even writing the compute intensive code in C++.
tl;dr: the type of benchmark chosen is stacked against node.
Node wasn't ever really meant to be used for CPU intensive tasks - especially the ones like this which you can fairly easy parallelize.
Longer than that. The sieve of Eratosthenes is attributed to Eratosthenes, who lived from 276 BC to 195 BC.
(defn prime? [n]
(if (even? n)
false
(let [root-plus-one (inc (int (Math/sqrt n)))]
(every? #(> (mod n %) 0) (range 3 root-plus-one 2)))))
(defn primes [n]
(conj (filter prime? (range 3 n)) 2))
As far as I can tell this is also faster on my machine, but as others suggest, I don't know that this is a particularly valuable benchmark.Furthermore, this isn't a great test. For one, you're specifically testing a performance profile that the JVM does not bother to optimise for (programs that run for less than about 20 seconds). For two, number speeds aren't a great measure - the issues with autoboxing (that I think Clojure does - I'm not a user) and whether the implementation is simply calling libgmp (maybe V8 is? Seems sensible to expect that it would - but I am also not a user of javascript) kind of predecide the outcome.