without looking at the code:
ranges in scala have been optimized in i think 2.10 to be able to be
inlineable completely when you iterate over them. at runtime, it
*should* be equal to a simple while loop and a counter variable
Am 03.02.2013 14:28, schrieb Jules:
> The Scala version is probably faster because it uses a range (1 to top)
> which is represented as a pair of integers (the start and endpoint).
> Perhaps the JVM can even eliminate that completely with escape analysis.
> The Java version is repeatedly filling an ArrayList with the numbers in
> that range.
> 
> On Sunday, February 3, 2013 12:19:51 PM UTC+1, Casper Clausen wrote:
> 
>     Given that I don't know much about how scala does optimizations, I
>     find the question of why the scala version is faster than the Java
>     version even more interesting.
> 
>     It seems to me that in Scala, the list (don't know the actual data
>     type which is created) of 1 to 20 is created each
>     time isDivisibleByAll is called which (probably?) creates some
>     overhead. 
> 
>     The Java version doesn't create the list for each check, but it uses
>     an ArrayList where it could use an array and Integer where it could
>     use int - shenedu makes that optimization in the buttom, but it only
>     improves about half a second according to him.
> 
>     So what's going on the Scala version?
> 
>     On Sunday, February 3, 2013 3:28:09 AM UTC+1, Alexandros Bantis wrote:
> 
>         Hello all. I'm working through the Project Euler problems in Java,
>         Scala, & Clojure (trying to learn all three?!?). I notice that
>         for one
>         particular problem, I use--more or less--a similar algorithm for
>         all
>         three, but the clojure code runs about 20-30 times slower than the
>         java/scala versions. Does anyone have any idea why this might
>         be? It
>         strikes me that it might have something to do with every? but I
>         don't
>         know because I'm a newbie with Clojure.
> 
>         
> http://stackoverflow.com/questions/14668272/what-can-i-do-to-speed-up-this-code
>         
> <http://stackoverflow.com/questions/14668272/what-can-i-do-to-speed-up-this-code>
> 
> 
>         thanks,
> 
>         alex
> 
> -- 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  


-- 

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to