[racket] Performance help

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sun Jan 4 13:30:53 EST 2015

On Jan 4, 2015, at 7:52 AM, Gustavo Massaccesi wrote:

> The original code is something like:
> 
>  (define ALPHABET (in-list (string->list "abc...xyz")))
>  (for/list ([c ALPHABET]))
>    (string-append "?" (string c) "?"))
> 
> The first problem is that outside a clause of a `for` the `in-list`
> creates a sequence. But inside a clause of a `for` the `in-list` is
> spliced and generates more efficient code.
> 
>  (define ALPHABET (string->list "abc...xyz"))
>  (for/list ([c (in-list ALPHABET)]))
>    (string-append "?" (string c) "?"))
> 
> The second problem is that for each word `(string c)` creates a new
> temporary string, so I mapped `string` at the definition site.
> 
>  (define ALPHABET (map string (string->list "abc...xyz")))
>  (for/list ([c (in-list ALPHABET)]))
>    (string-append "?" c "?"))
> 
> ---
> 
> Following the idea of the second change I tried to remove more of the
> temporary strings in the code ( for example, `(substring x 1)` looks
> like a bad idea). But my tries were unsuccessful to make the code
> faster :(.


I had experimented with these on my Mac and decided that it didn't matter. 
A near-10% improvement is not what I saw so thanks for the correction. 

-- Matthias


Posted on the users mailing list.