|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(use-modules (ice-9 syncase)) |
|
|
|
(define (PrintDiagnostics) |
|
(display " Total memory available= ???????? bytes") |
|
(display " Free memory= ???????? bytes") |
|
(newline)) |
|
|
|
|
|
|
|
(define (run-benchmark str thu) |
|
(display str) |
|
(thu)) |
|
|
|
|
|
|
|
(define-syntax let-class |
|
(syntax-rules |
|
() |
|
|
|
|
|
((let-class (((method . args) . method-body) ...) . body) |
|
(let () (define (method . args) . method-body) ... . body)) |
|
|
|
|
|
|
|
((let-class (((method . args) . method-body) ...) . body) |
|
(letrec-syntax ((method (syntax-rules () ((method . args) (begin . method-body)))) |
|
...) |
|
. body)) |
|
|
|
|
|
)) |
|
|
|
|
|
(define (gcbench kStretchTreeDepth) |
|
|
|
|
|
(define (TreeSize i) |
|
(- (expt 2 (+ i 1)) 1)) |
|
|
|
|
|
(define (NumIters i) |
|
(quotient (* 2 (TreeSize kStretchTreeDepth)) |
|
(TreeSize i))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(let* ((kLongLivedTreeDepth (- kStretchTreeDepth 2)) |
|
(kArraySize (* 4 (TreeSize kLongLivedTreeDepth))) |
|
(kMinTreeDepth 4) |
|
(kMaxTreeDepth kLongLivedTreeDepth)) |
|
|
|
|
|
|
|
(let-class (((make-node l r) |
|
(let ((v (make-empty-node))) |
|
(vector-set! v 0 l) |
|
(vector-set! v 1 r) |
|
v)) |
|
((make-empty-node) (make-vector 4 0)) |
|
((node.left node) (vector-ref node 0)) |
|
((node.right node) (vector-ref node 1)) |
|
((node.left-set! node x) (vector-set! node 0 x)) |
|
((node.right-set! node x) (vector-set! node 1 x))) |
|
|
|
|
|
(define (Populate iDepth thisNode) |
|
(if (<= iDepth 0) |
|
#f |
|
(let ((iDepth (- iDepth 1))) |
|
(node.left-set! thisNode (make-empty-node)) |
|
(node.right-set! thisNode (make-empty-node)) |
|
(Populate iDepth (node.left thisNode)) |
|
(Populate iDepth (node.right thisNode))))) |
|
|
|
|
|
(define (MakeTree iDepth) |
|
(if (<= iDepth 0) |
|
(make-empty-node) |
|
(make-node (MakeTree (- iDepth 1)) |
|
(MakeTree (- iDepth 1))))) |
|
|
|
(define (TimeConstruction depth) |
|
(let ((iNumIters (NumIters depth))) |
|
(display (string-append "Creating " |
|
(number->string iNumIters) |
|
" trees of depth " |
|
(number->string depth))) |
|
(newline) |
|
(run-benchmark "GCBench: Top down construction" |
|
(lambda () |
|
(do ((i 0 (+ i 1))) |
|
((>= i iNumIters)) |
|
(Populate depth (make-empty-node))))) |
|
(run-benchmark "GCBench: Bottom up construction" |
|
(lambda () |
|
(do ((i 0 (+ i 1))) |
|
((>= i iNumIters)) |
|
(MakeTree depth)))))) |
|
|
|
(define (main) |
|
(display "Garbage Collector Test") |
|
(newline) |
|
(display (string-append |
|
" Stretching memory with a binary tree of depth " |
|
(number->string kStretchTreeDepth))) |
|
(newline) |
|
(run-benchmark "GCBench: Main" |
|
(lambda () |
|
|
|
(MakeTree kStretchTreeDepth) |
|
|
|
|
|
(display (string-append |
|
" Creating a long-lived binary tree of depth " |
|
(number->string kLongLivedTreeDepth))) |
|
(newline) |
|
(let ((longLivedTree (make-empty-node))) |
|
(Populate kLongLivedTreeDepth longLivedTree) |
|
|
|
|
|
(display (string-append |
|
" Creating a long-lived array of " |
|
(number->string kArraySize) |
|
" inexact reals")) |
|
(newline) |
|
(let ((array (make-vector kArraySize 0.0))) |
|
(do ((i 0 (+ i 1))) |
|
((>= i (quotient kArraySize 2))) |
|
(vector-set! array i (/ 1.0 (exact->inexact i)))) |
|
(PrintDiagnostics) |
|
|
|
(do ((d kMinTreeDepth (+ d 2))) |
|
((> d kMaxTreeDepth)) |
|
(TimeConstruction d)) |
|
|
|
(if (or (eq? longLivedTree '()) |
|
(let ((n (min 1000 |
|
(- (quotient (vector-length array) |
|
2) |
|
1)))) |
|
(not (= (vector-ref array n) |
|
(/ 1.0 (exact->inexact |
|
n)))))) |
|
(begin (display "Failed") (newline))) |
|
|
|
|
|
|
|
)))) |
|
(PrintDiagnostics)) |
|
|
|
(main)))) |
|
|
|
(define (gc-benchmark . rest) |
|
(let ((k (if (null? rest) 18 (car rest)))) |
|
(display "The garbage collector should touch about ") |
|
(display (expt 2 (- k 13))) |
|
(display " megabytes of heap storage.") |
|
(newline) |
|
(display "The use of more or less memory will skew the results.") |
|
(newline) |
|
(run-benchmark (string-append "GCBench" (number->string k)) |
|
(lambda () (gcbench k))))) |
|
|
|
|
|
|
|
(gc-benchmark ) |
|
(display (gc-stats)) |
|
|