configurable read-string-buffer-size added by mario-goulart on Fri Oct 13 22:47:33 2017

$ cat read-buffer.scm
(use miscmacros posix utils)

(define (test2 fn)
  (with-input-from-file fn (cut read-string #f)))

(define (test3 fn)
  (read-all fn))


(for-each
 (lambda (mult)
   (read-string-buffer-size (* 1024 mult))

   (print "============= buffer size: " (read-string-buffer-size))

   (print "read-string")
   (time (dotimes (i 500) (test2 "5.json")))

   (print "read-all")
   (time (dotimes (i 500) (test3 "5.json"))))
 '(2 4 8 16 32))

$ csi -s read-buffer.scm
============= buffer size: 2048
read-string
1.928s CPU time, 1.424s GC time (major), 18706/1875 mutations (total/tracked), 885/615 GCs (major/minor), maximum live heap: 2.64 MiB
read-all
1.9s CPU time, 1.344s GC time (major), 16670/1869 mutations (total/tracked), 872/628 GCs (major/minor), maximum live heap: 2.64 MiB
============= buffer size: 4096
read-string
1.548s CPU time, 1.232s GC time (major), 16906/3814 mutations (total/tracked), 894/605 GCs (major/minor), maximum live heap: 2.14 MiB
read-all
1.544s CPU time, 1.208s GC time (major), 14870/3328 mutations (total/tracked), 867/632 GCs (major/minor), maximum live heap: 2.14 MiB
============= buffer size: 8192
read-string
1.264s CPU time, 0.948s GC time (major), 15988/2667 mutations (total/tracked), 628/871 GCs (major/minor), maximum live heap: 2.15 MiB
read-all
1.32s CPU time, 1.0s GC time (major), 13970/2664 mutations (total/tracked), 713/786 GCs (major/minor), maximum live heap: 2.15 MiB
============= buffer size: 16384
read-string
1.38s CPU time, 1.072s GC time (major), 15520/2589 mutations (total/tracked), 760/240 GCs (major/minor), maximum live heap: 2.17 MiB
read-all
0.64s CPU time, 0.396s GC time (major), 13520/2585 mutations (total/tracked), 277/723 GCs (major/minor), maximum live heap: 2.17 MiB
============= buffer size: 32768
read-string
0.78s CPU time, 0.496s GC time (major), 15304/2549 mutations (total/tracked), 351/649 GCs (major/minor), maximum live heap: 2.2 MiB
read-all
1.324s CPU time, 0.944s GC time (major), 13304/2054 mutations (total/tracked), 691/309 GCs (major/minor), maximum live heap: 2.2 MiB