10 extern void randomify_symbol_serials();
12 using namespace GiNaC;
14 /// make a string "1+x+2*x^2+...+n*x^n"
15 static string prepare_str(const unsigned n, const char x = 'x')
19 for (unsigned i = 2; i < n; i++)
20 s << '+' << i << '*' << x << '^' << i;
24 void benchmark_and_cmp(const string& srep, double& t_new, double& t_old)
29 ex e = the_parser(srep);
35 symtab syms = the_parser.get_syms();
36 const symbol x = find_or_insert_symbol("x", syms, true);
46 ex dif = (e - e2).expand();
48 cerr << "Got a difference: " << dif << endl;
49 throw std::logic_error("New and old parser give different results");
53 int main(int argc, char** argv)
55 cout << "timing GiNaC parser..." << flush;
56 randomify_symbol_serials();
57 unsigned n_min = 1024;
58 unsigned n_max = 32768;
60 n_max = atoi(argv[1]);
62 vector<double> times_new, times_old;
64 for (unsigned n = n_min; n <= n_max; n = n << 1) {
66 string srep = prepare_str(n);
67 benchmark_and_cmp(srep, t_new, t_old);
68 times_new.push_back(t_new);
69 times_old.push_back(t_old);
74 cout << "# terms new parser, s old parser, s" << endl;
75 for (size_t i = 0; i < times_new.size(); i++)
76 cout << " " << ns[i] << '\t' << times_new[i] << '\t' << times_old[i] << endl;