On Jun 17, 2014, at 22:24, Neil Van Dyke <n...@neilvandyke.org> wrote:

> Well, you could read only 10 times, rather than 4000000. :)
> 
> Another option is to do repeated regexp matching on the front of the file 
> input port, but I'd think "read" would be faster.  (Be sure to anchor the 
> regexp with "^" to the start of input, and experiment with limiting the 
> lookahead.)

Given that the file is fixed width, I came up with the following speed up:

        (time                                   ; 9464 ms
         (take
          (with-input-from-file path
            (lambda ()
              (for/list ([s (in-port (curry read-string 16))])
                (string->number (string-trim s)))))
          10))

tho, come to think of it, I'm not dealing with newlines properly...

Still, 3x slower than my doofy ruby version.


____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to