Measure unboxing via a struct mutable field
authorTony Garnock-Jones <tonygarnockjones@gmail.com>
Mon, 23 Jul 2018 18:40:59 +0100
changeset 412 e2a28341786a
parent 411 ba74f97d2ba9
child 413 99a706eaf2cf
Measure unboxing via a struct mutable field
experiments/little-smalltalk/bm-box.rkt
--- a/experiments/little-smalltalk/bm-box.rkt	Sun Jul 22 15:00:05 2018 +0100
+++ b/experiments/little-smalltalk/bm-box.rkt	Mon Jul 23 18:40:59 2018 +0100
@@ -10,6 +10,8 @@
 
 (define epoch 0)
 
+(struct quasi-box ([contents #:mutable]))
+
 (define (main)
   (define N 50000000)
 
@@ -41,6 +43,14 @@
   ;; (for [(i 5)] (time (by-embedding)))
   ;; (newline)
 
+  (define (by-unboxing-via-struct)
+    (define f (eval '(quasi-box (lambda (x) (+ x 1))) ns))
+    (for/fold [(x 0)] [(n (in-range N))] ((quasi-box-contents f) x)))
+
+  (printf "by-unboxing-via-struct\n")
+  (for [(i 5)] (time (by-unboxing-via-struct)))
+  (newline)
+
   (define (by-unboxing-with-check)
     (define f (eval `(letrec ((b (box (lambda (x)
                                         (if (> epoch ,epoch)