/mobile Handheld Friendly website
x64 Ubuntu : Intel® Q6600® quad-core |
Each table row shows performance measurements for this Racket program with a particular command-line input value N.
| N | CPU secs | Elapsed secs | Memory KB | Code B | ≈ CPU Load |
|---|---|---|---|---|---|
| 12 | 0.21 | 0.23 | 608 | 495 | 0% 0% 4% 100% |
| 16 | 1.67 | 1.68 | 83,740 | 495 | 1% 100% 0% 1% |
| 20 | 49.84 | 49.91 | 452,728 | 495 | 0% 100% 0% 0% |
Read the ↓ make, command line, and program output logs to see how this program was run.
Read binary-trees benchmark to see what this program should do.
Welcome to Racket v5.3.4.
#lang racket/base ;;; The Computer Language Benchmarks Game ;;; http://benchmarksgame.alioth.debian.org/ ;;; Derived from the Chicken variant by Sven Hartrumpf ;;; contributed by Matthew Flatt (require racket/cmdline) (struct node (left val right)) ;; Instead of (define-struct leaf (val)): (define (leaf val) (node #f val #f)) (define (leaf? l) (not (node-left l))) (define (leaf-val l) (node-val l)) (define (make item d) (if (= d 0) (leaf item) (let ((item2 (* item 2)) (d2 (- d 1))) (node (make (- item2 1) d2) item (make item2 d2))))) (define (check t) (if (leaf? t) (leaf-val t) (+ (node-val t) (- (check (node-left t)) (check (node-right t)))))) (define (main n) (let* ((min-depth 4) (max-depth (max (+ min-depth 2) n))) (let ((stretch-depth (+ max-depth 1))) (printf "stretch tree of depth ~a\t check: ~a\n" stretch-depth (check (make 0 stretch-depth)))) (let ((long-lived-tree (make 0 max-depth))) (for ((d (in-range 4 (add1 max-depth) 2))) (let ((iterations (arithmetic-shift 1 (+ (- max-depth d) min-depth)))) (printf "~a\t trees of depth ~a\t check: ~a\n" (* 2 iterations) d (for/fold ([c 0]) ([i (in-range iterations)]) (+ c (check (make i d)) (check (make (- i) d))))))) (printf "long lived tree of depth ~a\t check: ~a\n" max-depth (check long-lived-tree))))) (command-line #:args (n) (main (string->number n)))
Sat, 11 May 2013 15:52:50 GMT COMMAND LINE: /usr/local/src/racket-5.3.4/bin/racket binarytrees.racket 20 PROGRAM OUTPUT: stretch tree of depth 21 check: -1 2097152 trees of depth 4 check: -2097152 524288 trees of depth 6 check: -524288 131072 trees of depth 8 check: -131072 32768 trees of depth 10 check: -32768 8192 trees of depth 12 check: -8192 2048 trees of depth 14 check: -2048 512 trees of depth 16 check: -512 128 trees of depth 18 check: -128 32 trees of depth 20 check: -32 long lived tree of depth 20 check: -1