Created
July 9, 2019 14:17
-
-
Save shirok/03541b226c03e4f58926dc92d3764bef to your computer and use it in GitHub Desktop.
This file contains 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
(use gauche.time) | |
(define string (let1 o (open-output-string) | |
(do ((i 0 (+ i 1))) | |
((= i 1000) (get-output-string o)) | |
(write-char (integer->char i) o)))) | |
(define char-list0 (string->list string)) | |
(define char-list1 (string->list string)) | |
(define (->symbol cl) | |
(let1 o (open-output-string) | |
(write cl o) | |
(string->symbol (get-output-string o)))) | |
($ time-these/report 10000 | |
`((equal? . ,(^[] (equal? char-list0 char-list1))) | |
(loop . ,(^[] (let loop ((cl0 char-list0) (cl1 char-list1)) | |
(cond ((and (null? cl0) (null? cl1))) | |
((or (null? cl0) (null? cl1)) #f) | |
((char=? (car cl0) (car cl1)) | |
(loop (cdr cl0) (cdr cl1))) | |
(else #f))))) | |
(sym . ,(^[] (eq? (->symbol char-list0) (->symbol char-list1)))))) | |
#| | |
Benchmark: ran equal?, loop, sym, each for 10000 times. | |
equal?: 0.053 real, 0.050 cpu ( 0.050 user + 0.000 sys)@200000.00/s n=10000 | |
loop: 0.535 real, 0.530 cpu ( 0.530 user + 0.000 sys)@ 18867.92/s n=10000 | |
sym: 9.786 real, 14.150 cpu (13.970 user + 0.180 sys)@ 706.71/s n=10000 | |
Rate equal? loop sym | |
equal? 200000/s -- 10.600 283.000 | |
loop 18868/s 0.094 -- 26.698 | |
sym 707/s 0.004 0.037 -- | |
|# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment