[racket] why does in-indexed / in-range slow down my program?

From: Limbo Peng (iwinux at gmail.com)
Date: Sun Jan 20 22:33:00 EST 2013


Hi Matthias,

On 01/20, Matthias Felleisen wrote:
> I can confirm a serious speed-up with the explicit vector-ref inside the for loop instead of the for-loop lookup with (in-vector ...). I get from 20s to 12s on my reasonably new (small) macair. 
> 
> When you look at the expansion, you see the expected two-argument for-loop function with two arguments instead of one. You will also see an unsafe-vector-ref for the for-loop, while our code contains a normal vector-ref. So the question is whether the compiler generates code for two-argument recursive functions that is so much worse than for a one-argument function with a safe vector ref. Curious. 

I've tested your revised version - here's the output:

Output: cpu time: 26907 real time: 26979 gc time: 142

It is 1~2 seconds faster but not much. Maybe this is its limit?

Here's two additional questions:

1. how can I check the expansion of the for-loop? I'm using the Racket REPL from CLI.
2. I've noticed that the let-form in my code is replaced by "define", is this the preferred coding style?

Thanks.

-Limbo Peng


Posted on the users mailing list.