;; test.scm (use miscmacros posix) (define (test fn) (let* ((fd (file-open fn open/rdonly)) (size (file-size fd)) (str (file-read fd size))) (file-close fd) str)) (define (test2 fn) (with-input-from-file fn (cut read-string #f))) (print "file-read") (time (dotimes (i 100) (test "5.json"))) (print "read-string") (time (dotimes (i 100) (test2 "5.json"))) ;; test.py import timeit def test(): with open("5.json") as fd: foo = fd.read() print(timeit.timeit('test()', number=100, setup="from __main__ import test")) ;; Results kooda@crocmou /t/json> csi -s test.scm file-read 13.885s CPU time, 7.541s GC time (major), 16/0 mutations (total/tracked), 99/1 GCs (major/minor), maximum live heap: 149.82 MiB read-string 50.264s CPU time, 14.572s GC time (major), 65636/10572 mutations (total/tracked), 239/7461 GCs (major/minor), maximum live heap: 129.11 MiB kooda@crocmou /t/json> python3 test.py 21.95156424200104