See what automatically invalidating stale procedures might cost.
authorTony Garnock-Jones <tonygarnockjones@gmail.com>
Tue, 17 Jul 2018 13:31:28 +0100
changeset 391 1d4b8c5e18a4
parent 390 bfd7d4e7f498
child 392 618244a1ee07
See what automatically invalidating stale procedures might cost.
experiments/little-smalltalk/bm-box.rkt
--- a/experiments/little-smalltalk/bm-box.rkt	Tue Jul 17 13:26:57 2018 +0100
+++ b/experiments/little-smalltalk/bm-box.rkt	Tue Jul 17 13:31:28 2018 +0100
@@ -8,6 +8,8 @@
 (define-namespace-anchor ns-anchor)
 (define ns (namespace-anchor->namespace ns-anchor))
 
+(define epoch 0)
+
 (define (main)
   (define N 50000000)
 
@@ -34,6 +36,21 @@
     (for/fold [(x 0)] [(n (in-range N))] (f x)))
 
   (for [(i 5)] (time (by-embedding)))
-  (newline))
+  (newline)
+
+  (define (by-unboxing-with-check)
+    (define f (eval `(letrec ((b (box (lambda (x)
+                                        (if (> epoch ,epoch)
+                                            (begin (set-box! b (lambda (x) (+ x 2)))
+                                                   ((unbox b) x))
+                                            (+ x 1))))))
+                       b)
+                    ns))
+    (for/fold [(x 0)] [(n (in-range N))] ((unbox f) x)))
+
+  (for [(i 5)] (time (by-unboxing-with-check)))
+  (newline)
+
+  )
 
 (module+ main (main))