1 /** @file time_parser.cpp
6 * GiNaC Copyright (C) 1999-2020 Johannes Gutenberg University Mainz, Germany
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.
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.
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
25 using namespace GiNaC;
36 extern void randomify_symbol_serials();
38 /// make a string "1+x+2*x^2+...+n*x^n"
39 static string prepare_str(const unsigned n, const char x = 'x')
43 for (unsigned i = 2; i < n; i++)
44 s << '+' << i << '*' << x << '^' << i;
48 static double benchmark_and_cmp(const string& srep)
53 ex e = the_parser(srep);
54 const double t = RSD10.read();
58 int main(int argc, char** argv)
60 cout << "timing GiNaC parser..." << flush;
61 randomify_symbol_serials();
62 unsigned n_min = 1024;
63 unsigned n_max = 32768;
65 n_max = atoi(argv[1]);
69 for (unsigned n = n_min; n <= n_max; n = n << 1) {
70 string srep = prepare_str(n);
71 const double t = benchmark_and_cmp(srep);
77 cout << "# terms time, s" << endl;
78 for (size_t i = 0; i < times.size(); i++)
79 cout << " " << ns[i] << '\t' << times[i] << endl;