Merge remote-tracking branch 'origin/master' into for-steve
[sxemacs] / modules / ase / ase-heap-profs.el
1 ;;;  ase-profs.el -- Benchmarks for ASE
2 ;; Copyright (C) 2006, 2007 Sebastian Freundt
3 ;;
4 ;; Author: Sebastian Freundt <hroptatyr@sxemacs.org>
5 ;; Keywords: tests
6 ;;
7 ;; This file is part of SXEmacs.
8 ;;
9 ;; Redistribution and use in source and binary forms, with or without
10 ;; modification, are permitted provided that the following conditions
11 ;; are met:
12 ;;
13 ;; 1. Redistributions of source code must retain the above copyright
14 ;;    notice, this list of conditions and the following disclaimer.
15 ;;
16 ;; 2. Redistributions in binary form must reproduce the above copyright
17 ;;    notice, this list of conditions and the following disclaimer in the
18 ;;    documentation and/or other materials provided with the distribution.
19 ;;
20 ;; 3. Neither the name of the author nor the names of any contributors
21 ;;    may be used to endorse or promote products derived from this
22 ;;    software without specific prior written permission.
23 ;;
24 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
25 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 ;; DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ;;
36 ;;; Synched up with: Not in FSF.
37 ;;
38 ;;; Commentary:
39 ;; See benchmark.el for instructions on how to run these tests.
40
41 (condition-case nil
42     (require 'benchmark)
43   (file-error
44    (push "." load-path)
45    (when (and (boundp 'load-file-name) (stringp load-file-name))
46      (push (expand-file-name "../tests/benchmark"
47                              (file-name-directory load-file-name))
48            load-path))
49    (require 'benchmark)))
50
51 (require 'ase-heap)
52
53
54 (defun heap-fill (N)
55   "heap filling"
56   (while (nonnegativep N)
57     (ase-add-heap h (random most-positive-fixnum))
58     (setq N (1- N))))
59
60 (defun heap-dump-d (N)
61   "heap -> dllist"
62   (ase-heap-to-dllist h))
63
64 (defun heap-dump-v (N)
65   "heap -> vector"
66   (ase-heap-to-vector h))
67
68 (defun heap-dump-l (N)
69   "heap -> list"
70   (ase-heap-to-list h))
71
72 (defun heap-dump-d* (N)
73   "heap -> dllist*"
74   (ase-heap-to-dllist* h))
75
76 (defun heap-dump-v* (N)
77   "heap -> vector*"
78   (ase-heap-to-vector* h))
79
80 (defun heap-dump-l* (N)
81   "heap -> list*"
82   (ase-heap-to-list* h))
83
84
85 (defun yheap-constr (N)
86   "dyna heap construction"
87   (setq h (ase-heap :kind 'dynamic)))
88
89 (defun yheap-destr (N)
90   "dyna heap cleanup"
91   (setq h nil)
92   (garbage-collect))
93
94 (defun dheap-constr (N)
95   "dense heap construction"
96   (setq h (ase-heap :kind 'dense)))
97
98 (defun dheap-destr (N)
99   "dense heap cleanup"
100   (setq h nil)
101   (garbage-collect))
102
103 (defun wheap-constr (N)
104   "weak heap construction"
105   (setq h (ase-heap :kind 'weak)))
106
107 (defun wheap-destr (N)
108   "weak heap cleanup"
109   (setq h nil)
110   (garbage-collect))
111
112
113
114 ;; now the actual test suites
115 (bm-estimate-time
116  (list
117   :test-funv [yheap-constr heap-fill heap-dump-d heap-dump-d*]
118   :test-range '(10 . 100000)
119   :plot-file "benchmark-yheap.plot"))
120
121 (bm-estimate-time
122  (list
123   :test-funv [dheap-constr heap-fill heap-dump-d heap-dump-d*]
124   :test-range '(10 . 100000)
125   :plot-file "benchmark-dheap.plot"))
126
127 (bm-estimate-time
128  (list
129   :test-funv [wheap-constr heap-fill heap-dump-d heap-dump-d*]
130   :test-range '(10 . 100000)
131   :plot-file "benchmark-wheap.plot"))
132
133
134 ;; ase-heap-profs.el ends here