Merge branch 'upstream/1.16' into tizen_gst_1.16.2
[platform/upstream/gstreamer.git] / tests / benchmarks / mass-elements.scm
1 #!/bin/bash
2 # -*- scheme -*-
3 exec guile -s $0 "$@"
4 !#
5
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
21
22 ;; Quick hack to make some data files that gnuplot can read from
23 ;; mass-elements. Guile 1.6.
24
25 (use-modules (srfi srfi-13)
26              (srfi srfi-1)
27              (ice-9 optargs)
28              (ice-9 popen))
29
30 (define *phases* '(create set run destroy))
31
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))))))
40
41 (define (run-test n-identities)
42   (format #t "; running test: ~a\n" n-identities)
43   (let lp ((in (read-lines
44                 (open-input-pipe
45                  (format #f "./mass-elements ~A"
46                          (number->string n-identities)))))
47            (out '()))
48     (if (null? in)
49         (begin
50           (or (eq? (length out) 4) (error "Invalid mass_elements output"))
51           (map cons *phases* (reverse! out)))
52         (let ((line (car in)))
53           (if (eqv? (string-ref line 0) #\*)
54               (lp (cdr in) out)
55               (lp (cdr in)
56                   (cons (fold (lambda (x ret) (+ (* ret 60) x)) 0
57                               (map (lambda (x) (with-input-from-string x read))
58                                    (string-split line #\:)))
59                         out)))))))
60
61 (define (run-tests start stop step)
62   (let lp ((n start) (out '()))
63     (if (> n stop)
64         (reverse! out)
65         (lp (+ n step)
66             (acons n (run-test n) out)))))
67
68 (define (output-results results)
69   (let ((p (open-output-file "mass_elements.data")))
70     (display "#num_identities creation state-change run destroy\n" p)
71     (let lp ((in results))
72       (if (not (null? in))
73           (let* ((line (car in))
74                  (n (car line)))
75             (display n p)
76             (for-each
77              (lambda (t) (format p " ~a" t))
78              (map cdr (cdr line)))
79             (newline p)
80             (lp (cdr in)))))
81     (close-port p)))
82
83 (output-results
84  (apply run-tests (map string->number (cdr (program-arguments)))))