-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharray1.scm.scm
89 lines (74 loc) · 2.49 KB
/
array1.scm.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
;;------------------------------------------------------------------------------
;; Macros
(##define-macro (def-macro form . body)
`(##define-macro ,form (let () ,@body)))
;;------------------------------------------------------------------------------
;; Functions used by LC to get time info
(def-macro (##lc-time expr)
(let ((sym (gensym)))
`(let ((r (##lc-exec-stats (lambda () ,expr))))
(##print-perm-string "CPU time: ")
(##print-double (+ (cdr (assoc "User time" (cdr r)))
(cdr (assoc "Sys time" (cdr r)))))
(##print-perm-string "\n")
(##print-perm-string "GC CPU time: ")
(##print-double (+ (cdr (assoc "GC user time" (cdr r)))
(cdr (assoc "GC sys time" (cdr r)))))
(##print-perm-string "\n")
(map (lambda (el)
(##print-perm-string (car el))
(##print-perm-string ": ")
(##print-double (cdr el))
(##print-perm-string "\n"))
(cdr r))
r)))
(define (##lc-exec-stats thunk)
(let* ((at-start (##process-statistics))
(result (thunk))
(at-end (##process-statistics)))
(define (get-info msg idx)
(cons msg
(- (f64vector-ref at-end idx)
(f64vector-ref at-start idx))))
(list
result
(get-info "User time" 0)
(get-info "Sys time" 1)
(get-info "Real time" 2)
(get-info "GC user time" 3)
(get-info "GC sys time" 4)
(get-info "GC real time" 5)
(get-info "Nb gcs" 6))))
;;------------------------------------------------------------------------------
(define (run-benchmark name count ok? run-maker . args)
(let ((run (apply run-maker args)))
(let ((result (car (##lc-time (run)))))
result)))
;;; ARRAY1 -- One of the Kernighan and Van Wyk benchmarks.
(define (create-x n)
(define result (make-vector n))
(do ((i 0 (+ i 1)))
((>= i n) result)
(vector-set! result i i)))
(define (create-y x)
(let* ((n (vector-length x))
(result (make-vector n)))
(do ((i (- n 1) (- i 1)))
((< i 0) result)
(vector-set! result i (vector-ref x i)))))
(define (my-try n)
(vector-length (create-y (create-x n))))
(define (go n)
(let loop ((repeat 100)
(result '()))
(if (> repeat 0)
(loop (- repeat 1) (my-try n))
result)))
(define (main . args)
(run-benchmark
"array1"
1
(lambda (result) (equal? result 200000))
(lambda (n) (lambda () (go n)))
200000))
(main)