<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: What *warn-on-reflection* doesn&#8217;t tell you about arrays</title>
	<atom:link href="http://clj-me.cgrand.net/2009/08/06/what-warn-on-reflection-doesnt-tell-you-about-arrays/feed/" rel="self" type="application/rss+xml" />
	<link>http://clj-me.cgrand.net/2009/08/06/what-warn-on-reflection-doesnt-tell-you-about-arrays/</link>
	<description>When the pupil is ready to learn, a teacher will appear.</description>
	<lastBuildDate>Mon, 30 Jan 2012 20:57:36 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Timothy Pratley</title>
		<link>http://clj-me.cgrand.net/2009/08/06/what-warn-on-reflection-doesnt-tell-you-about-arrays/comment-page-1/#comment-45</link>
		<dc:creator>Timothy Pratley</dc:creator>
		<pubDate>Mon, 28 Sep 2009 13:00:33 +0000</pubDate>
		<guid isPermaLink="false">http://clj-me.cgrand.net/2009/08/06/what-warn-on-reflection-doesnt-tell-you-about-arrays/#comment-45</guid>
		<description>Ah, thanks!</description>
		<content:encoded><![CDATA[<p>Ah, thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cgrand</title>
		<link>http://clj-me.cgrand.net/2009/08/06/what-warn-on-reflection-doesnt-tell-you-about-arrays/comment-page-1/#comment-44</link>
		<dc:creator>cgrand</dc:creator>
		<pubDate>Mon, 28 Sep 2009 09:55:32 +0000</pubDate>
		<guid isPermaLink="false">http://clj-me.cgrand.net/2009/08/06/what-warn-on-reflection-doesnt-tell-you-about-arrays/#comment-44</guid>
		<description>@Timothy, I think your tests are dominated by boxed arithmetic.
(let [a #^doubles (make-array Double/TYPE 100)]
(time (dotimes [i 100000000] (aget a (int (rem i 100))))))
&quot;Elapsed time: 1806.106502 msecs&quot;
user=&gt; (let [a (make-array Double/TYPE 100)]
(time (dotimes [i 100000000] (aget a (int (rem i 100))))))
&quot;Elapsed time: 17794.809466 msecs&quot;

Note that dotimes automatically hints &#039;i as an int.

I measure this difference even for smaller arrays:
user=&gt; (let [a #^doubles (make-array Double/TYPE 100)]
(time (dotimes [i 100000] (aget a (int (rem i 100))))))
&quot;Elapsed time: 14.871513 msecs&quot;
user=&gt; (let [a (make-array Double/TYPE 100)]
(time (dotimes [i 100000] (aget a (int (rem i 100))))))
&quot;Elapsed time: 30.586988 msecs&quot;

When I hint your code to perform primitive arithmetic, I get similar improvements:
user=&gt; (let [a (make-array Double/TYPE 1000000)
b #^doubles (make-array Double/TYPE 1000000)]
(time (doseq [i (range 1000), j (range 1000)] (aget a (int (+ (int i) (* (int j) 100))))))
(time (doseq [i (range 1000), j (range 1000)] (aget b (int (+ (int i) (* (int j) 100)))))))
&quot;Elapsed time: 415.131113 msecs&quot;
&quot;Elapsed time: 209.553309 msecs&quot;</description>
		<content:encoded><![CDATA[<p>@Timothy, I think your tests are dominated by boxed arithmetic.<br />
(let [a #^doubles (make-array Double/TYPE 100)]<br />
(time (dotimes [i 100000000] (aget a (int (rem i 100))))))<br />
&#8220;Elapsed time: 1806.106502 msecs&#8221;<br />
user=> (let [a (make-array Double/TYPE 100)]<br />
(time (dotimes [i 100000000] (aget a (int (rem i 100))))))<br />
&#8220;Elapsed time: 17794.809466 msecs&#8221;</p>
<p>Note that dotimes automatically hints &#8216;i as an int.</p>
<p>I measure this difference even for smaller arrays:<br />
user=> (let [a #^doubles (make-array Double/TYPE 100)]<br />
(time (dotimes [i 100000] (aget a (int (rem i 100))))))<br />
&#8220;Elapsed time: 14.871513 msecs&#8221;<br />
user=> (let [a (make-array Double/TYPE 100)]<br />
(time (dotimes [i 100000] (aget a (int (rem i 100))))))<br />
&#8220;Elapsed time: 30.586988 msecs&#8221;</p>
<p>When I hint your code to perform primitive arithmetic, I get similar improvements:<br />
user=> (let [a (make-array Double/TYPE 1000000)<br />
b #^doubles (make-array Double/TYPE 1000000)]<br />
(time (doseq [i (range 1000), j (range 1000)] (aget a (int (+ (int i) (* (int j) 100))))))<br />
(time (doseq [i (range 1000), j (range 1000)] (aget b (int (+ (int i) (* (int j) 100)))))))<br />
&#8220;Elapsed time: 415.131113 msecs&#8221;<br />
&#8220;Elapsed time: 209.553309 msecs&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Timothy Pratley</title>
		<link>http://clj-me.cgrand.net/2009/08/06/what-warn-on-reflection-doesnt-tell-you-about-arrays/comment-page-1/#comment-42</link>
		<dc:creator>Timothy Pratley</dc:creator>
		<pubDate>Sun, 27 Sep 2009 12:58:29 +0000</pubDate>
		<guid isPermaLink="false">http://clj-me.cgrand.net/2009/08/06/what-warn-on-reflection-doesnt-tell-you-about-arrays/#comment-42</guid>
		<description>Hmmm actually I do see a speed-up for larger samples:

(let [a (make-array Double/TYPE 1000000)
b #^doubles (make-array Double/TYPE 1000000)]
(time (doseq [i (range 1000), j (range 1000)] (aget a (int (+ i (* j 100))))))
(time (doseq [i (range 1000), j (range 1000)] (aget b (int (+ i (* j 100)))))))
&quot;Elapsed time: 1452.764384 msecs&quot;
&quot;Elapsed time: 1118.704557 msecs&quot;</description>
		<content:encoded><![CDATA[<p>Hmmm actually I do see a speed-up for larger samples:</p>
<p>(let [a (make-array Double/TYPE 1000000)<br />
b #^doubles (make-array Double/TYPE 1000000)]<br />
(time (doseq [i (range 1000), j (range 1000)] (aget a (int (+ i (* j 100))))))<br />
(time (doseq [i (range 1000), j (range 1000)] (aget b (int (+ i (* j 100)))))))<br />
&#8220;Elapsed time: 1452.764384 msecs&#8221;<br />
&#8220;Elapsed time: 1118.704557 msecs&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Timothy Pratley</title>
		<link>http://clj-me.cgrand.net/2009/08/06/what-warn-on-reflection-doesnt-tell-you-about-arrays/comment-page-1/#comment-41</link>
		<dc:creator>Timothy Pratley</dc:creator>
		<pubDate>Sun, 27 Sep 2009 10:59:26 +0000</pubDate>
		<guid isPermaLink="false">http://clj-me.cgrand.net/2009/08/06/what-warn-on-reflection-doesnt-tell-you-about-arrays/#comment-41</guid>
		<description>opps the comment ate the tags,
they are ins tags that are leaking through.</description>
		<content:encoded><![CDATA[<p>opps the comment ate the tags,<br />
they are ins tags that are leaking through.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Timothy Pratley</title>
		<link>http://clj-me.cgrand.net/2009/08/06/what-warn-on-reflection-doesnt-tell-you-about-arrays/comment-page-1/#comment-40</link>
		<dc:creator>Timothy Pratley</dc:creator>
		<pubDate>Sun, 27 Sep 2009 10:58:35 +0000</pubDate>
		<guid isPermaLink="false">http://clj-me.cgrand.net/2009/08/06/what-warn-on-reflection-doesnt-tell-you-about-arrays/#comment-40</guid>
		<description>Very interesting!

Sadly this trick doesn&#039;t seem to work for arrays of primitives, or my syntax is wrong?

(let [a (make-array Double/TYPE 10000)
      b #^doubles (make-array Double/TYPE 10000)]
  (time (doseq [i (range 100), j (range 100)] (aget a (int (+ i (* j 100))))))
  (time (doseq [i (range 100), j (range 100)] (aget b (int (+ i (* j 100)))))))

Also... is there any way to get (aget a i j) to be fast - or do I have to go with a flat array and calc the offsets?

Btw looks like a small bit of markup leaked into your code on the new site:
&quot;...&quot;
It doesn&#039;t appear on the old site.</description>
		<content:encoded><![CDATA[<p>Very interesting!</p>
<p>Sadly this trick doesn&#8217;t seem to work for arrays of primitives, or my syntax is wrong?</p>
<p>(let [a (make-array Double/TYPE 10000)<br />
      b #^doubles (make-array Double/TYPE 10000)]<br />
  (time (doseq [i (range 100), j (range 100)] (aget a (int (+ i (* j 100))))))<br />
  (time (doseq [i (range 100), j (range 100)] (aget b (int (+ i (* j 100)))))))</p>
<p>Also&#8230; is there any way to get (aget a i j) to be fast &#8211; or do I have to go with a flat array and calc the offsets?</p>
<p>Btw looks like a small bit of markup leaked into your code on the new site:<br />
&#8220;&#8230;&#8221;<br />
It doesn&#8217;t appear on the old site.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

