[racket] Perlin and simplex noise - optimizing Racket code

From: JP Verkamp (racket at jverkamp.com)
Date: Fri Apr 12 16:23:07 EDT 2013

> There shouldn't be any difference. AFAIK, Float is a synonym for Flonum.
>

I think the odd timing results that I got (with Real/Flonum the same and
Float faster) was actually a result of other changes that I was making as I
went. Float/Flonum being the same thing is a bit strange at times, since
the errors don't seem particularly consistent on which they use (I expect
it's whichever one was used in the particular type declaration I'm breaking
and those vary).

In case anyone is interested in the final timing here are all of the steps
(running from command line Racket rather than DrRacket). I'll write up a
better blog post detailing the process and the steps along the way probably
this weekend.

*Untyped code, generating an image, git: b2d12e4*
 perlin: cpu time: 355 real time: 356 gc time: 40
simplex: cpu time: 243 real time: 242 gc time: 4

*Typed code with Real, no wrapper, generating an image, git: 006faf9*
 perlin: cpu time: 235 real time: 236 gc time: 15
simplex: cpu time: 147 real time: 147 gc time: 4

*Typed code with Float, wrapper converting Real to Float, generating an
image, git: 5da0723*
 perlin: cpu time: 112 real time: 118 gc time: 23
simplex: cpu time: 106 real time: 110 gc time: 3

Originally I was confused because building the images was actually faster
than just using the data directly. But then I realized that
timing-tests.rkt wasn't Typed. It's kind of amazing how much that helps...
Now I'm seeing about 50-60ms of overhead just to create the image which you
had mentioned as well.

*Typed code with Float, wrapper, not generating an image, git: 7445311*
 perlin: cpu time: 41 real time: 40 gc time: 0
simplex: cpu time: 52 real time: 52 gc time: 2

I'm not sure how much better even *could* be done at this point.
Particularly since the original code that mine is based on--In Java, not C.
Oops--runs a 256x256 without making an image in ~30ms. So we're definitely
in the same ballpark now.

Racket macros and languages don't generally distinguish paren shapes. (It's
> hard to preserve that syntax property as macros expand.) IOW, this works
> because `[...]' isn't special:
>
> (: build-perlin-image (Integer Integer (#:scale Real) -> flomap))
>

Right. I was still hoping that would be how to signify optional parameters.
Although that wouldn't work since the same sort of shape is used for
signifying Listof/Vectorof/etc. I'm unsure if there's anything that is the
only item in a list though.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130412/bfa65ac4/attachment.html>

Posted on the users mailing list.