Merge branch 'move_subdir' into tizen_gst_1.19.2_mono
[platform/upstream/gstreamer.git] / subprojects / gstreamer / tests / benchmarks / complexity.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 ;; complexity. Guile 1.8.
24
25 (use-modules (srfi srfi-13)
26              (srfi srfi-1)
27              (ice-9 optargs)
28              (ice-9 popen)
29              (ice-9 rdelim))
30
31 (define *phases* '(create set run destroy))
32
33 (define (read-lines port)
34   (let lp ((lines '()))
35     (let ((x (read-line port)))
36       (if (eof-object? x)
37           (begin
38             (close-port port)
39             (reverse! lines))
40           (lp (cons x lines))))))
41
42 (define (parse-time str)
43   (and (char-numeric? (string-ref str 0))
44        (fold (lambda (x ret) (+ (* ret 60) x)) 0
45              (map (lambda (x) (with-input-from-string x read))
46                   (string-split str #\:)))))
47
48 (define (run-test program . args)
49   (format #t "; running test: ~a\n" (cons program args))
50   (map
51    cons
52    *phases*
53    (filter-map
54     parse-time
55     (read-lines
56      (open-input-pipe
57       (string-join (map object->string (cons program args)) " "))))))
58
59 (define (seq start stop step)
60   (let lp ((n start) (out '()))
61     (if (> n stop)
62         (reverse! out)
63         (lp (+ n step) (cons n out)))))
64
65 (define (run-tests n-elements)
66   (let lp ((x 1) (out '()))
67     (if (> x n-elements)
68         (reverse! out)
69         (lp (* x 2)
70             (acons x (run-test "./complexity" x n-elements) out)))))
71
72 (define (output-results results)
73   (let ((p (open-output-file "complexity.data")))
74     (display "#complexity creation state-change run destroy\n" p)
75     (for-each
76      (lambda (line)
77        (display (car line) p)
78        (for-each
79         (lambda (t) (format p " ~a" t))
80         (map cdr (cdr line)))
81        (newline p))
82      results)
83     (close-port p)))
84
85 (output-results
86  (apply run-tests (map string->number (cdr (program-arguments)))))