-#include <iostream>
-#include <string>
-#include <sstream>
+/** @file time_parser.cpp
+ *
+ * Time the parser. */
+
+/*
+ * GiNaC Copyright (C) 1999-2020 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 <cstddef>
#include <cstdlib>
-#include <vector>
+#include <iostream>
+#include <sstream>
#include <stdexcept>
-#include "ginac.h"
-#include "timer.h"
-extern void randomify_symbol_serials();
+#include <string>
+#include <vector>
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')
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)
if (argc > 1)
n_max = atoi(argv[1]);
- vector<double> times_new, times_old;
+ vector<double> times;
vector<unsigned> 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;
}