1 #!/bin/bash
2 # -*- scheme -*-
3 exec guile -s $0 "$@"
4 !#
6 ;; Copyright (C) 2005 Andy Wingo
7 ;;
8 ;; This library is free software; you can redistribute it and/or
9 ;; modify it under the terms of the GNU Lesser General Public
10 ;; License as published by the Free Software Foundation; either
11 ;; version 2.1 of the License, or (at your option) any later version.
12 ;;
13 ;; This library is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ;; Lesser General Public License for more details.
17 ;;
18 ;; You should have received a copy of the GNU Lesser General Public
19 ;; License along with this library; if not, write to the Free Software
20 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 ;; Quick hack to make some data files that gnuplot can read from
23 ;; complexity. Guile 1.6.
25 (use-modules (srfi srfi-13)
26 (srfi srfi-1)
27 (ice-9 optargs)
28 (ice-9 popen))
30 (define *phases* '(create set run destroy))
32 (define (read-lines port)
33 (let lp ((lines '()))
34 (let ((x (read-line port)))
35 (if (eof-object? x)
36 (begin
37 (close-port port)
38 (reverse! lines))
39 (lp (cons x lines))))))
41 (define (parse-time str)
42 (and (char-numeric? (string-ref str 0))
43 (fold (lambda (x ret) (+ (* ret 60) x)) 0
44 (map (lambda (x) (with-input-from-string x read))
45 (string-split str #\:)))))
47 (define (run-test program . args)
48 (format #t "; running test: ~a\n" (cons program args))
49 (map
50 cons
51 *phases*
52 (filter-map
53 parse-time
54 (read-lines
55 (open-input-pipe
56 (string-join (map object->string (cons program args)) " "))))))
58 (define (seq start stop step)
59 (let lp ((n start) (out '()))
60 (if (> n stop)
61 (reverse! out)
62 (lp (+ n step) (cons n out)))))
64 (define (run-tests n-elements)
65 (let lp ((x 1) (out '()))
66 (if (> x n-elements)
67 (reverse! out)
68 (lp (* x 2)
69 (acons x (run-test "./complexity" x n-elements) out)))))
71 (define (output-results results)
72 (let ((p (open-output-file "complexity.data")))
73 (display "#complexity creation state-change run destroy\n" p)
74 (for-each
75 (lambda (line)
76 (display (car line) p)
77 (for-each
78 (lambda (t) (format p " ~a" t))
79 (map cdr (cdr line)))
80 (newline p))
81 results)
82 (close-port p)))
84 (output-results
85 (apply run-tests (map string->number (cdr (program-arguments)))))