18 ms·
Trial division (your algorithm) _is_ linear time, there exist better than linear time algorithms for this, and they're pretty easy to understand (look for Solov
by calpaterson 16y ago
Trial division (your algorithm) _is_ linear time, there exist better than linear time algorithms for this, and they're pretty easy to understand (look for Solovay-Strassen on wikipedia for a simple one).
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.