<div dir="ltr">FWIW, my push speeds up the any-wrap/c implementation a bunch. Those two should have similar speeds after you get that, I guess.<div><br></div><div>Robby</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Thu, Dec 12, 2013 at 11:03 AM, Neil Toronto <span dir="ltr"><<a href="mailto:neil.toronto@gmail.com" target="_blank">neil.toronto@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I tried your branch that implements it and saw about 3.5x speedup for the `magnitude*' test. This is of course without Robby's recent first-order contract changes.<br>
<br>
(I think it's about 3.5x: I tried with magnitude* : Number -> Any first and got 2400ms on the easy tests. I changed it to magnitude* : Number -> Number and got 690ms. Apparently, for an `Any' return type, an `any-wrap/c' contract is generated instead of nothing. If that's much faster to check than `number?', though, the speedup is even better.)<br>

<br>
I'd love to see this with Robby's recent changes. Hint? Nudge? Please?<br>
<br>
I didn't see very much speedup with arrays (about 1.2x). Speed tests on the math library's distribution objects were very interesting, though, and indicate why the arrays might not be much faster. Here's my test program:<br>

<br>
<br>
#lang racket<br>
<br>
(require math/distributions)<br>
<br>
(define d (normal-dist 0 1))<br>
<br>
(printf "pdf d 0~n")<br>
(for ([_  (in-range 5)])<br>
  (time (for ([_  (in-range 100000)])<br>
          (pdf d 0))))<br>
(newline)<br>
<br>
(define p (distribution-pdf d))<br>
(printf "p 0~n")<br>
(for ([_  (in-range 5)])<br>
  (time (for ([_  (in-range 100000)])<br>
          (p 0))))<br>
(newline)<br>
<br>
<br>
The two tests are equivalent, as `pdf' just pulls the pdf function out of the distribution struct and applies it. In TR, the tests are exactly the same speed (extremely fast). In untyped Racket, on the main branch, the second test is 16x faster, and on your branch, it's 44x faster. (It's still 10x slower than TR on your branch, so again... I'd love to see your changes and Robby's together. :D)<span class="HOEnZb"><font color="#888888"><br>

<br>
Neil ⊥</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
On 12/12/2013 12:40 AM, Eric Dobson wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Removing the return value checking is in the works. It actually is<br>
removing all of the checks that would blame typed code, so higher<br>
order functions/datastructure get improvements too. It is actually<br>
functional the last time I checked, but lacking documentation which is<br>
what is holding up merging with mainline.<br>
<br>
<a href="https://github.com/plt/racket/pull/453" target="_blank">https://github.com/plt/racket/<u></u>pull/453</a><br>
<br>
On Wed, Dec 11, 2013 at 7:57 PM, Robby Findler<br>
<<a href="mailto:robby@eecs.northwestern.edu" target="_blank">robby@eecs.northwestern.edu</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I see that TR's type->contract returns<br>
<br>
  (-> (flat-named-contract (quote Float) flonum?) (flat-named-contract (quote<br>
Float) flonum?))<br>
<br>
for the type (Float -> Float), but it could return<br>
<br>
  (-> (flat-named-contract (quote Float) flonum?) any)<br>
<br>
which wouldn't do any result value checking (this being different from any/c<br>
as the range of the arrow contract).<br>
<br>
Robby<br>
<br>
<br>
On Wed, Dec 11, 2013 at 6:18 PM, Neil Toronto <<a href="mailto:neil.toronto@gmail.com" target="_blank">neil.toronto@gmail.com</a>><br>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
On 12/11/2013 02:49 PM, Neil Toronto wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
On 12/11/2013 01:55 PM, Stephen Bloch wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
On Dec 11, 2013, at 2:36 PM, Neil Toronto wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
numeric primitives implemented in Typed Racket are faster than the<br>
same primitives implemented in C.<br>
</blockquote></blockquote>
<br>
<br>
Whoa!  How did that happen?<br>
</blockquote>
<br>
<br>
Whoa! That's not what I meant! O_o<br>
<br>
I said "we might be getting close" to that. I haven't tried porting a<br>
numeric C primitive to TR yet, but I have a hunch that it'll still be<br>
slower. I'll try one now and report what I find.<br>
<br>
Neil ⊥<br>
</blockquote>
<br>
<br>
I can't figure out why `flsinh' is faster to call from untyped Racket than<br>
`sinh'. All my tests with a Typed Racket `magnitude' show calls from untyped<br>
code are significantly slower, except in the one case that it computes<br>
Euclidean distance. That case is only twice as slow.<br>
<br>
I've attached the benchmark program. The `magnitude*' function is more or<br>
less a direct translation of `magnitude' from "number.c" into Typed Racket.<br>
Here's a summary of the results I get on my computer, in milliseconds, for 5<br>
million calls from untyped Racket, by data type.<br>
<br>
<br>
Function         Flonum  Rational  Fixnum  Integer  Float-Complex<br>
------------------------------<u></u>------------------------------<u></u>-------<br>
magnitude*         385      419      378     414         686<br>
magnitude           59       44       40      40         390<br>
<br>
<br>
The only one that's close in relative terms is Float-Complex. The others<br>
just call `abs'. The decompiled code doesn't show any inlining of<br>
`magnitude', so this comparison should be good.<br>
<br>
I'll bet checking the return value contract (which is unnecessary) is the<br>
main slowdown. It has to check for number of values.<br>
<br>
For comparison, here are the timings for running the benchmarks in TR with<br>
#:no-optimize:<br>
<br>
<br>
Function         Flonum  Rational  Fixnum  Integer  Float-Complex<br>
------------------------------<u></u>------------------------------<u></u>-------<br>
magnitude*          45       70*      37     102*       318<br>
magnitude           61       45       39      91*       394<br>
<br>
                                               * = unexpectedly high<br>
<br>
<br>
Here's what I understand from comparing the numbers:<br>
<br>
  * Except for non-fixnum integers, calling `magnitude' in TR is just as<br>
fast as in untyped Racket. I have no idea why it would be slower on big<br>
integers. That's just weird.<br>
<br>
  * Calling `abs' in Racket is faster than calling `scheme_abs' in C,<br>
except on rationals and big integers.<br>
<br>
  * Operating on flonums in Typed Racket, using generic numeric functions,<br>
is faster than doing the same in C.<br>
<br>
Overall, it looks like the TR code is within the same order of magnitude<br>
(pun not intended) as the C code. I would love to try this benchmark with<br>
either 1) a `magnitude*' with an `AnyValues' return type; or 2) a contract<br>
boundary that doesn't check TR's return types for first-order functions.<br>
<br>
(I managed to make a `magnitude*' with type Number -> AnyValues, but TR<br>
couldn't make a contract for it.)<br>
<br>
Neil ⊥<br>
<br>
<br>
_________________________<br>
   Racket Developers list:<br>
   <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/<u></u>dev</a><br>
<br>
</blockquote>
<br>
_________________________<br>
   Racket Developers list:<br>
   <a href="http://lists.racket-lang.org/dev" target="_blank">http://lists.racket-lang.org/<u></u>dev</a><br>
<br>
</blockquote></blockquote>
<br>
</div></div></blockquote></div><br></div>