Performance example of Transducers added by DeeEff on Sat Jan 14 20:32:59 2023
kassogtha ~/Code/playground $ cat transducer-bench.scm (import transducers (rename (only srfi-1 iota) (iota list-iota))) (define xs (list-iota 100000000)) (time (transduce list-fold (compose (filter odd?) (map (lambda (x) (* 3 x)))) (collect-list) xs)) kassogtha ~/Code/playground $ csc -O3 -static transducer-bench.scm kassogtha ~/Code/playground $ ./transducer-bench 6.505s CPU time, 2.717s GC time (major), 49999999/1 mutations (total/tracked), 1/85516 GCs (major/minor), maximum live heap: 3.35 GiB kassogtha ~/Code/playground $ cat filter-map-bench.scm (import (only srfi-1 iota)) (define xs (iota 100000000)) (define (filter-map pred? mapfunc lst) (let loop ((l lst) (r '())) (if (null? l) (reverse r) (loop (cdr l) (if (pred? (car l)) (cons (mapfunc (car l)) r) r))))) (time (filter-map odd? (lambda (x) (* 3 x)) xs)) kassogtha ~/Code/playground $ csc -O3 -static filter-map-bench.scm kassogtha ~/Code/playground $ ./filter-map-bench 6.076s CPU time, 2.693s GC time (major), 1/58783 GCs (major/minor), maximum live heap: 3.35 GiB ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kassogtha ~/Code/playground $ cat transducer-bench-2.scm (import transducers) (time (transduce range-fold (compose (filter odd?) (map (lambda (x) (* 3 x)))) (collect-list) (iota 100000000))) kassogtha ~/Code/playground $ csc -O3 -static transducer-bench-2.scm kassogtha ~/Code/playground $ ./transducer-bench-2 5.879s CPU time, 1.428s GC time (major), 49999999/1 mutations (total/tracked), 8/109926 GCs (major/minor), maximum live heap: 1.12 GiB