[racket] help me speed up string split?

From: Ryan Davis (zenspider at gmail.com)
Date: Wed Jun 18 02:03:28 EDT 2014

On Jun 17, 2014, at 22:24, Neil Van Dyke <neil at 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.



Posted on the users mailing list.