9 #include "parser/parser.hpp"
11 extern void randomify_symbol_serials();
13 using namespace GiNaC;
15 /// make a string "1+x+2*x^2+...+n*x^n"
16 static string prepare_str(const unsigned n, const char x = 'x')
20 for (unsigned i = 2; i < n; i++)
21 s << '+' << i << '*' << x << '^' << i;
25 void benchmark_and_cmp(const string& srep, double& t_new, double& t_old)
30 ex e = the_parser(srep);
36 symtab syms = the_parser.get_syms();
37 const symbol x = find_or_insert_symbol("x", syms, true);
47 ex dif = (e - e2).expand();
49 cerr << "Got a difference: " << dif << endl;
50 throw std::logic_error("New and old parser give different results");
54 int main(int argc, char** argv)
56 cout << "timing GiNaC parser..." << flush;
57 randomify_symbol_serials();
58 unsigned n_min = 1024;
59 unsigned n_max = 32768;
61 n_max = atoi(argv[1]);
63 vector<double> times_new, times_old;
65 for (unsigned n = n_min; n <= n_max; n = n << 1) {
67 string srep = prepare_str(n);
68 benchmark_and_cmp(srep, t_new, t_old);
69 times_new.push_back(t_new);
70 times_old.push_back(t_old);
75 cout << "# terms new parser, s old parser, s" << endl;
76 for (size_t i = 0; i < times_new.size(); i++)
77 cout << " " << ns[i] << '\t' << times_new[i] << '\t' << times_old[i] << endl;