Created
August 14, 2019 12:25
-
-
Save shirok/d032ba542623986a67cc864ccde6a5f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#| | |
Benchmark: ran srfi-42-sum, apply-filter-iota, fold-lseq, recursive-loop, each for 1000 times. | |
srfi-42-sum: 3.722 real, 3.720 cpu ( 3.720 user + 0.000 sys)@268.82/s n=1000 | |
apply-filter-iota: 14.721 real, 23.980 cpu (23.840 user + 0.140 sys)@ 41.70/s n=1000 | |
fold-lseq: 43.668 real, 50.560 cpu (50.460 user + 0.100 sys)@ 19.78/s n=1000 | |
recursive-loop: 4.371 real, 4.370 cpu ( 4.370 user + 0.000 sys)@228.83/s n=1000 | |
Rate srfi-42-sum apply-filter-iota fold-lseq recursive-loop | |
srfi-42-sum 269/s -- 6.446 13.591 1.175 | |
apply-filter-iota 42/s 0.155 -- 2.108 0.182 | |
fold-lseq 20/s 0.074 0.474 -- 0.086 | |
recursive-loop 229/s 0.851 5.487 11.570 -- | |
|# | |
(use gauche.time) | |
(use srfi-42) | |
(define (srfi-42-sum n) | |
(sum-ec (:range i 1 n) (if (even? i)) i)) | |
(define (apply-filter-iota n) | |
(apply + (filter even? (iota n 1)))) | |
(define (fold-lseq n) | |
(fold + 0 (lfilter even? (liota n 1)))) | |
(define (recursive-loop n) | |
(let loop ([i 1] [s 0]) | |
(if (= i n) s (loop (+ i 1) (if (even? i) (+ s i) s))))) | |
(define N 100000) | |
($ time-these/report 1000 | |
`((srfi-42-sum . ,(cut srfi-42-sum N)) | |
(apply-filter-iota . ,(cut apply-filter-iota N)) | |
(fold-lseq . ,(cut fold-lseq N)) | |
(recursive-loop . ,(cut recursive-loop N)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment