#lang racket (require logbook) (define E (standard-logbook-entry (default-logbook #:verbose? #t) "minimart" "hash-size")) (define Ttime (logbook-table E "timing" #:column-spec '(initial-count wallclock-secs/entry entries/wallclock-sec cpu+gc-sec wallclock-sec gc-sec final-count))) (define T (logbook-table E "measurements" #:column-spec '(number-of-entries bytes-per-entry current-memory-use))) (define *the-hash* (hash)) (define *zero-datapoint* #f) (define (record-datapoint!) (collect-garbage) (collect-garbage) (collect-garbage) (define latest-datapoint (current-memory-use)) (define n (hash-count *the-hash*)) (when (not *zero-datapoint*) (set! *zero-datapoint* latest-datapoint)) (define delta (- latest-datapoint *zero-datapoint*)) (define perentry (/ delta (exact->inexact n))) (write-logbook-datum! T (list n perentry latest-datapoint))) (record-datapoint!) (let loop ((next-count 1000)) (when (< next-count 5000000) (define old-count (hash-count *the-hash*)) (define-values (ignorable-results cpu+gc-time wallclock-time gc-time) (time-apply (lambda () (let inner-loop ((n old-count)) (when (< n next-count) (set! *the-hash* (hash-set *the-hash* n n)) (inner-loop (+ n 1))))) '())) (define cpu+gc-sec (/ cpu+gc-time 1000.0)) (define wallclock-sec (/ wallclock-time 1000.0)) (define gc-sec (/ gc-time 1000.0)) (write-logbook-datum! Ttime (list old-count (/ wallclock-sec (- next-count old-count)) (and (positive? wallclock-sec) (/ (- next-count old-count) wallclock-sec)) cpu+gc-sec wallclock-sec gc-sec next-count)) (record-datapoint!) (loop (inexact->exact (truncate (* next-count 1.2))))))