-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.ljsp
51 lines (44 loc) · 1.55 KB
/
benchmark.ljsp
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
;; WRITE ME (should provide octave-compatible output for benchmarking a single-argument function over an integer range)
(require 'stuff)
(require 'java)
(setq +newline+ #\
)
;; (defun bench (fun range outfile)
;; (let ((start (first range))
;; (end (second range))
;; (step (or (third range) 1)))
;; (with-open-file (stream outfile out)
;; (dotimes (i (1+ (- end start)))
;; (let ((i (* (+ i start) step)))
;; (write-string (cut-string-at-char (with-output-to-string (*standard-output*)
;; (time (fun i)))
;; +newline+)
;; stream)
;; (write-string " " stream)))
;; (write-char +newline+ stream))))
(defun min-array (ar)
(let ((min (field-value Long 'MAX_VALUE)))
(dotimes (i (length ar))
(when (< (aref ar i) min)
(setq min (aref ar i))))
min))
(defun time-fn (fn arg times)
(let ((result (make-array times)))
(dotimes (i times)
(let ((t0 (get-time)))
(fn arg)
(aset result i (- (get-time) t0))))
result))
(defun bench (fun range outfile)
(let ((start (first range))
(end (second range))
(step (or (third range) 1)))
(with-open-file (stream outfile out)
(dotimes (i (1+ (/ (- end start) step)))
(let ((i (* (+ i start) step)))
(print i)
(prin1 (min-array (time-fn fun i 30)) stream)
(write-string " " stream)))
(write-char +newline+ stream))
nil))
(provide 'benchmark)