From 23a9fe858c01c6905486e1a87ac46553482e3802 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Tue, 5 Aug 2025 11:01:40 +0200 Subject: Actually use both different sets The original implementation just diffed the same set with itself, and needed a workaround for srfi-1's shortcut on the identical list. Since we're comparing to other implementations with differing sets, it makes sense to do the same here. We actually started doing this but ended up just redefining the same list... --- benchmarks/benchmark.scm | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'benchmarks/benchmark.scm') diff --git a/benchmarks/benchmark.scm b/benchmarks/benchmark.scm index 6ef4044..1b42aa9 100644 --- a/benchmarks/benchmark.scm +++ b/benchmarks/benchmark.scm @@ -27,8 +27,8 @@ (lp (add1 i) (cons (fun i) res))))) -(define lst (list-tabulate size (lambda (i) (string->symbol (conc "x" i))))) -(define lst (list-tabulate size (lambda (i) (string->symbol (conc "y" i))))) +(define lst1 (list-tabulate size (lambda (i) (string->symbol (conc "x" i))))) +(define lst2 (list-tabulate size (lambda (i) (string->symbol (conc "y" i))))) ;; Super-hacky way to determine impact of caching the hash value in a symbol. ;; We abuse the symbol's toplevel value slot to store the hash. A slightly @@ -160,31 +160,36 @@ (let lp ((i 10000)) (case impl ((lset) - (lset-difference eq? lst (cons 'aha lst))) + (lset-difference eq? lst1 lst2)) ((slset) - (slset-difference lst (cons 'aha lst))) + (slset-difference lst1 lst2)) ((symbolset cached-symbolset) (when (eq? impl 'cached-symbolset) (set! symbol-cache? #t)) - (symbolset-difference lst (cons 'aha lst))) + (symbolset-difference lst1 lst2)) ((hash-table cached-hash-table) - (when (pair? lst) + (when (pair? lst1) (when (eq? impl 'cached-hash-table) (set! symbol-cache? #t)) - (let ((ht (make-my-hash-table size))) + (let ((ht1 (make-my-hash-table size)) + (ht2 (make-my-hash-table size))) (begin - (for-each (lambda (x) (my-hash-table-set! ht x #t)) lst) - (set! lst ht)))) - (my-hash-table-difference lst lst)) + (for-each (lambda (x) (my-hash-table-set! ht1 x #t)) lst1) + (for-each (lambda (x) (my-hash-table-set! ht2 x #t)) lst2) + (set! lst1 ht1) + (set! lst2 ht2)))) + (my-hash-table-difference lst1 lst2)) ((srfi-69 cached-srfi-69) - (when (pair? lst) + (when (pair? lst1) (when (eq? impl 'cached-srfi-69) (set! symbol-cache? #t)) - (let ((ht (make-hash-table eq? (if (eq? impl 'cached-srfi-69) hash-symbol symbol-hash) size))) - (begin - (for-each (lambda (x) (hash-table-set! ht x #t)) lst) - (set! lst ht)))) - (srfi-69-hash-table-difference lst lst)) + (let ((ht1 (make-hash-table eq? (if (eq? impl 'cached-srfi-69) hash-symbol symbol-hash) size)) + (ht2 (make-hash-table eq? (if (eq? impl 'cached-srfi-69) hash-symbol symbol-hash) size))) + (for-each (lambda (x) (hash-table-set! ht1 x #t)) lst1) + (for-each (lambda (x) (hash-table-set! ht2 x #t)) lst2) + (set! lst1 ht1) + (set! lst2 ht2))) + (srfi-69-hash-table-difference lst1 lst2)) (else (error "Unknown impl" impl))) (unless (zero? i) (lp (sub1 i)))) -- cgit v1.2.3