X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=check%2Ftime_parser.cpp;h=48437df33aeace49f5bc6b303ea6614f04c28380;hp=273163648c6c30be360329778f5e5d1413e132d5;hb=c19c2786ec3345720f0358a08bf8f781dcde0f02;hpb=dbe5029ed72f406f45ec2a9d3584a828653ab34a diff --git a/check/time_parser.cpp b/check/time_parser.cpp index 27316364..48437df3 100644 --- a/check/time_parser.cpp +++ b/check/time_parser.cpp @@ -1,15 +1,39 @@ -#include -#include -#include +/** @file time_parser.cpp + * + * Time the parser. */ + +/* + * GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "ginac.h" +#include "timer.h" +using namespace GiNaC; + #include #include -#include +#include +#include #include -#include "ginac.h" -#include "timer.h" -extern void randomify_symbol_serials(); +#include +#include using namespace std; -using namespace GiNaC; + +extern void randomify_symbol_serials(); /// make a string "1+x+2*x^2+...+n*x^n" static string prepare_str(const unsigned n, const char x = 'x') @@ -21,33 +45,14 @@ static string prepare_str(const unsigned n, const char x = 'x') return s.str(); } -void benchmark_and_cmp(const string& srep, double& t_new, double& t_old) +static double benchmark_and_cmp(const string& srep) { parser the_parser; timer RSD10; RSD10.start(); ex e = the_parser(srep); - t_new = RSD10.read(); - RSD10.stop(); - if (t_new > 2.0) - cout << '.' << flush; - - symtab syms = the_parser.get_syms(); - const symbol x = find_or_insert_symbol("x", syms, true); - lst sl; - sl = x; - RSD10.start(); - ex e2(srep, sl); - t_old = RSD10.read(); - - if (t_old > 2.0) - cout << '.' << flush; - - ex dif = (e - e2).expand(); - if (!dif.is_zero()) { - cerr << "Got a difference: " << dif << endl; - throw std::logic_error("New and old parser give different results"); - } + const double t = RSD10.read(); + return t; } int main(int argc, char** argv) @@ -59,20 +64,18 @@ int main(int argc, char** argv) if (argc > 1) n_max = atoi(argv[1]); - vector times_new, times_old; + vector times; vector ns; for (unsigned n = n_min; n <= n_max; n = n << 1) { - double t_new, t_old; string srep = prepare_str(n); - benchmark_and_cmp(srep, t_new, t_old); - times_new.push_back(t_new); - times_old.push_back(t_old); + const double t = benchmark_and_cmp(srep); + times.push_back(t); ns.push_back(n); } cout << "OK" << endl; - cout << "# terms new parser, s old parser, s" << endl; - for (size_t i = 0; i < times_new.size(); i++) - cout << " " << ns[i] << '\t' << times_new[i] << '\t' << times_old[i] << endl; + cout << "# terms time, s" << endl; + for (size_t i = 0; i < times.size(); i++) + cout << " " << ns[i] << '\t' << times[i] << endl; return 0; }