2009/11/15 ajuc <aju...@gmail.com>:
>
>> That's very odd.
>>
>> Rich needs to take a look at this. Letting a constant shouldn't have a
>> performance hit, IMO.
>>
>> Could you test whether it's faster to use your complex data structure
>> directly in the function, anonymously at the point of use, or to yank it
>> from a global var?
>
> Code (can you run it on your computer to verify?):
> http://clojure.pastebin.com/f508ad31b

Here are my results on Linux with the server VM, after fixing the typo
(glocal -> global) and changing pr to println:

http://clojure.pastebin.com/f49f16d71

"Elapsed time: 2110.721659 msecs"
point-to-hilbert-directly-from-global  nil

"Elapsed time: 1197.547328 msecs"
point-to-hilbert-let-from-global  nil

"Elapsed time: 1884.777766 msecs"
point-to-hilbert-literal-in-let  nil

"Elapsed time: 4847.630084 msecs"
point-to-hilbert-literal-in-place  nil

$ java -version
java version "1.6.0_0"
OpenJDK Runtime Environment (IcedTea6 1.4.1) (6b14-1.4.1-0ubuntu12)
OpenJDK Client VM (build 14.0-b08, mixed mode, sharing)

Although, running it again now, I get:

"Elapsed time: 3278.709938 msecs"
point-to-hilbert-directly-from-global  nil

"Elapsed time: 1234.739782 msecs"
point-to-hilbert-let-from-global  nil

"Elapsed time: 1945.980422 msecs"
point-to-hilbert-literal-in-let  nil

"Elapsed time: 5737.756701 msecs"
point-to-hilbert-literal-in-place  nil

And after rearranging them, I get:

"Elapsed time: 2506.30872 msecs"
point-to-hilbert-let-from-global  nil

"Elapsed time: 2091.866122 msecs"
point-to-hilbert-literal-in-let  nil

"Elapsed time: 1309.805767 msecs"
point-to-hilbert-directly-from-global  nil

"Elapsed time: 5228.071194 msecs"
point-to-hilbert-literal-in-place  nil

So it seems you need to allow Hotspot to optimise it:

"Elapsed time: 3084.796868 msecs"
point-to-hilbert-literal-in-let  nil

"Elapsed time: 1354.13218 msecs"
point-to-hilbert-literal-in-let  nil

"Elapsed time: 1340.907318 msecs"
point-to-hilbert-literal-in-let  nil

"Elapsed time: 1338.655641 msecs"
point-to-hilbert-literal-in-let  nil

and:

"Elapsed time: 2393.682633 msecs"
point-to-hilbert-let-from-global  nil

"Elapsed time: 990.713252 msecs"
point-to-hilbert-let-from-global  nil

"Elapsed time: 1008.451391 msecs"
point-to-hilbert-let-from-global  nil

"Elapsed time: 985.379787 msecs"
point-to-hilbert-let-from-global  nil

-- 
Michael Wood <esiot...@gmail.com>

-- 
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

Reply via email to