Tail-recursive string->list pasted by lennonboy on Fri Mar 24 22:49:40 2017

(define (string->list s)
  (##sys#check-string s 'string->list)
  (let ((len (##sys#size s)))
    (let loop ((i 0) (ls '()))
      (if (fx= i len)
	  ls
	  (loop (fx+ i 1)
		(cons (##core#inline "C_subchar" s i) ls))))))

Reversing the walk order on the string pasted by DeeEff on Fri Mar 24 22:59:05 2017

(define (string->list s)
  (##sys#check-string s 'string->list)
  (let ((len (##sys#size s)))
    (let loop ((i (fx- len 1)) (ls '()))
      (if (fx< i 0)
	  ls
	  (loop (fx- i 1)
		(cons (##core#inline "C_subchar" s i) ls))))))

The benchmark thingie added by lemonboy on Fri Mar 24 23:14:45 2017

(define (my-string->list s)
  (##sys#check-string s 'string->list)
  (let ((len (##sys#size s)))
    (let loop ((i (fx- len 1)) (ls '()))
      (if (fx< i 0)
	  ls
	  (loop (fx- i 1)
		(cons (##core#inline "C_subchar" s i) ls))))))

(define *corpus*
  `("foo" "bar" "baaaaaaaaaaaaaaar" ""
    "lorem ipsum dolor sit amet"
    ,(make-string 1000 #\a)
    ,(make-string 5000 #\a)
    ,(make-string 10000 #\a)))

(gc #t)
(time
  (let lp ((i 10000)) (unless (fx= i -1) (map my-string->list *corpus*) (lp (fx- i 1)))))
(gc #t)
(time
  (let lp ((i 10000)) (unless (fx= i -1) (map    string->list *corpus*) (lp (fx- i 1)))))
;; 11.604s CPU time, 6.214s GC time (major), 160016/18245 mutations (total/tracked), 4643/2766 GCs (major/minor), maximum live heap: 628.45 KiB
;; 25.413s CPU time, 15.476s GC time (major), 160016/34176 mutations (total/tracked), 12229/4957 GCs (major/minor), maximum live heap: 698.44 KiB