]> www.ginac.de Git - ginac.git/blob - check/time_parser.cpp
Fixed bug in multivariate factorization. Fractional numerical content was not
[ginac.git] / check / time_parser.cpp
1 #include <iostream>
2 #include <string>
3 #include <sstream>
4 #include <cstddef>
5 #include <cstdlib>
6 #include <vector>
7 #include <stdexcept>
8 #include "ginac.h"
9 #include "timer.h"
10 extern void randomify_symbol_serials();
11 using namespace std;
12 using namespace GiNaC;
13
14 /// make a string "1+x+2*x^2+...+n*x^n"
15 static string prepare_str(const unsigned n, const char x = 'x')
16 {
17         ostringstream s;
18         s << x;
19         for (unsigned i = 2; i < n; i++)
20                 s << '+' << i << '*' << x << '^' << i; 
21         return s.str();
22 }
23
24 static double benchmark_and_cmp(const string& srep)
25 {
26         parser the_parser;
27         timer RSD10;
28         RSD10.start();
29         ex e = the_parser(srep);
30         const double t = RSD10.read();
31         return t;
32 }
33
34 int main(int argc, char** argv)
35 {
36         cout << "timing GiNaC parser..." << flush;
37         randomify_symbol_serials();
38         unsigned n_min = 1024;
39         unsigned n_max = 32768;
40         if (argc > 1)
41                 n_max = atoi(argv[1]);
42
43         vector<double> times;
44         vector<unsigned> ns;
45         for (unsigned n = n_min; n <= n_max; n = n << 1) {
46                 string srep = prepare_str(n);
47                 const double t = benchmark_and_cmp(srep);
48                 times.push_back(t);
49                 ns.push_back(n);
50         }
51
52         cout << "OK" << endl;
53         cout << "# terms  time, s" << endl;
54         for (size_t i = 0; i < times.size(); i++)
55                 cout << " " << ns[i] << '\t' << times[i] << endl;
56         return 0;
57 }