]> www.ginac.de Git - ginac.git/blob - check/times.cpp
Fixed bug in gcd (patch from Sheplyakov Alexei).
[ginac.git] / check / times.cpp
1 /** @file times.cpp
2  *
3  *  Main program that calls the individual timings. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2005 Johannes Gutenberg University Mainz, Germany
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program 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
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 #include <stdexcept>
24 #include "times.h"
25
26 /** Generate a random amount of symbols and destroy them again immediatly.
27  *  This operation effectively makes the serial numbers of all subsequent
28  *  symbols unpredictable.  If the serials are unpredictable, then so are
29  *  their hash values.  If the hash values are unpredictable, then so are
30  *  the canonical orderings.  If the canonical orderings are unpredictable,
31  *  all subsequent times are subject to some variation.  This variation,
32  *  however is natural and desireable for two reasons: First, we cannot know
33  *  how many symbols have been generated before in real world computations.
34  *  Second, the following timings are subject to some semi-random variation
35  *  anyways because short timings need to be repeated until enough time has
36  *  gone by for the measurement to be reliable.  During this process the serial
37  *  numbers will be shifted anyways in a semi-random way.  It is better not
38  *  to lull the user in a false sense of reproducibility and instead confront
39  *  her with the normal variation to be expected.
40  */
41 void randomify_symbol_serials()
42 {
43         srand((unsigned)time(NULL));
44         const int m = rand() % 666;
45         for (int s=0; s<m; ++s ) {
46                 symbol* tmp = new symbol;
47                 delete tmp;
48         }
49 }
50
51 int main()
52 {
53         randomify_symbol_serials();
54
55         unsigned result = 0;
56         
57 #define TIME(which) \
58 try { \
59         result += time_ ## which (); \
60 } catch (const exception &e) { \
61         cout << "Error: caught exception " << e.what() << endl; \
62         ++result; \
63 }
64
65         TIME(dennyfliegner)
66         TIME(gammaseries)
67         TIME(vandermonde)
68         TIME(toeplitz)
69         TIME(hashmap)
70         TIME(lw_A)
71         TIME(lw_B)
72         TIME(lw_C)
73         TIME(lw_D)
74         TIME(lw_E)
75         TIME(lw_F)
76         TIME(lw_G)
77         TIME(lw_H)
78         TIME(lw_IJKL)
79         TIME(lw_M1)
80         TIME(lw_M2)
81         TIME(lw_N)
82         TIME(lw_O)
83         TIME(lw_P)
84         TIME(lw_Pprime)
85         TIME(lw_Q)
86         TIME(lw_Qprime)
87         TIME(antipode)
88         TIME(fateman_expand)
89         
90         if (result) {
91                 cout << "Error: something went wrong. ";
92                 if (result == 1) {
93                         cout << "(one failure)" << endl;
94                 } else {
95                         cout << "(" << result << " individual failures)" << endl;
96                 }
97                 cout << "please check times.out against times.ref for more details."
98                      << endl << "happy debugging!" << endl;
99         }
100         
101         return result;
102 }