It&#39;s interesting that if I use (in-vector ...) in the for/fold statements, the times for the for/fold version are about the same as for the (uglier) do version (with vector-refs). [This one probably would benefit from Matthew&#39;s performance improvements.] Actually using it would mean giving up the flexibility in going to sequences in the first place, but it means there is some hope of eventually getting the same performance for the sequence versions (at least for vectors).<br>
<br>using in-vector in the for<br>cpu time: 266 real time: 265 gc time: 0<br>cpu time: 250 real time: 250 gc time: 47<br><br>current science collection routines<br>cpu time: 250 real time: 249 gc time: 0<br>cpu time: 218 real time: 218 gc time: 16<br>
<br>It would be nice if (for ((x some-vector)) ...) and (for ((x (in-vector some-vector))) ...) had similar performance. I realize that at expansion time the latter knows to expect a vector while the former does not and can generate code accordingly. But, I can dream.<br>
<br><div class="gmail_quote">On Wed, Sep 9, 2009 at 9:37 AM, Doug Williams <span dir="ltr">&lt;<a href="mailto:m.douglas.williams@gmail.com">m.douglas.williams@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Thanks for running them for me.  I guess it comes down to whether the flexibility is worth the performance hit. I like the flexibility. In the past there were times I have had to convert lists to vectors just to compute statistics on them, which is even less efficient.  I could include the old ones as vector-mean, vector-variance, etc for people who need/want the performance.<br>
<font color="#888888">
<br>Doug</font><div><div></div><div class="h5"><br><br><div class="gmail_quote">On Wed, Sep 9, 2009 at 9:29 AM, Matthew Flatt <span dir="ltr">&lt;<a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I don&#39;t think the latest changes will affect the performance, since<br>
unsafe operations are only used for `in-vector&#39; and (sometimes)<br>
`in-range&#39; when they appear immediately in a `for&#39; right-hand side.<br>
<br>
Times on my machine:<br>
<br>
 New<br>
  laptop% mzscheme time-statistics.ss<br>
  cpu time: 576 real time: 578 gc time: 11<br>
  cpu time: 450 real time: 451 gc time: 10<br>
  (that&#39;s without `in-vector&#39;; times using `in-vector&#39; are the same)<br>
<br>
 Old<br>
  laptop% mzscheme time-statistics.ss<br>
  cpu time: 233 real time: 237 gc time: 18<br>
  cpu time: 196 real time: 198 gc time: 10<br>
<div><div></div><div><br>
At Wed, 9 Sep 2009 09:18:55 -0600, Doug Williams wrote:<br>
&gt; I&#39;ve reimplemented the statistics module from the science collection to use<br>
&gt; sequences instead of just vectors. I like the generality better - I can use<br>
&gt; any sequence (e.g., vector or list) - but there is more of performance hit<br>
&gt; than I would have liked. I haven&#39;t timed it with the new changes that<br>
&gt; Matthew just put it. The good news is that there isn&#39;t much of a hit for<br>
&gt; using (variance data) as opposed to (variance (in-vector data)) and there<br>
&gt; isn&#39;t a huge hit for using the contract that ensures that the sequence is a<br>
&gt; sequence of real numbers.<br>
&gt;<br>
&gt; I created a 100000 element vector and timed a loop getting the variance of<br>
&gt; the elements 10 times. Note that I create an executable that runs compiled<br>
&gt; code in both cases. [Runs of the sequence code within DrScheme are about<br>
&gt; twice the times of the compiled code - I assume they run from byte code in<br>
&gt; that case. Runs of the science collection code is about the same in DrScheme<br>
&gt; - I assume they run the compiled code.]<br>
&gt;<br>
&gt; Times using sequences [primarily using &#39;for/fold&#39; for sequencing and<br>
&gt; referencing]:<br>
&gt;<br>
&gt; (variance data) : cpu time: 625 real time: 625 gc time: 32<br>
&gt; (unchecked-variance data) : cpu time: 531 real time: 531 gc time: 77<br>
&gt;<br>
&gt; (variance (in-vector data)) : cpu time: 609 real time: 609 gc time: 16<br>
&gt; (unchecked-variance (in-vector data)) : cpu time: 485 real time: 484 gc<br>
&gt; time: 0<br>
&gt;<br>
&gt; Times using vectors (current science collection routines) [primarily using<br>
&gt; &#39;do&#39; for sequencing with &#39;vector-ref&#39; for referencing]:<br>
&gt;<br>
&gt; (variance data) : cpu time: 235 real time: 234 gc time: 16<br>
&gt; (unchecked-variance data) : cpu time: 187 real time: 188 gc time: 46<br>
&gt;<br>
&gt; All of the normal caveats about timing values apply - just because I&#39;m<br>
&gt; timing a statistics routine doesn&#39;t been it&#39;s statistically relevant :).<br>
&gt;<br>
&gt; I will retime them when there is a nightly build with Matthew&#39;s performance<br>
&gt; improvements is available (it seems that 4.2.1.7 from Saturday is the<br>
&gt; latest) - or I build it on my machine at home. I don&#39;t have the development<br>
&gt; tools on my laptop to build from svn.<br>
&gt;<br>
&gt; I&#39;ve attached the files in case anyone wants to look them over. If someone<br>
&gt; could run them against the latest svn, it would be nice. [<br>
&gt;<br>
&gt; Comments from anyone that uses these routines from the science collection<br>
&gt; would be most welcome.<br>
&gt;<br>
&gt; Doug<br>
<br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>