1 /** @file time_hashmap.cpp
3 * Timings for exhashmap<> operations. */
6 * GiNaC Copyright (C) 1999-2008 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
28 using namespace GiNaC;
31 static void run_timing(unsigned size, double &time_insert, double &time_find, double &time_erase)
38 for (unsigned i=0; i<size; ++i)
39 S.push_back(symbol());
42 for (unsigned i=0; i<size; ++i)
43 M[S[i]] = S[(i+1)%size];
44 time_insert = t.read();
47 for (unsigned i=0; i<size; ++i) {
48 if (!M[S[i]].is_equal(S[(i+1)%size])) {
49 clog << "map lookup failed" << endl;
56 for (unsigned i=0; i<size; ++i) {
57 if (M.erase(S[i]) != 1) {
58 clog << "erasing element " << S[i] << " failed" << endl;
63 clog << "map not empty (size = " << M.size() << ") after erasing all elements" << endl;
66 time_erase = t.read();
70 unsigned time_hashmap()
74 cout << "timing hash map operations" << flush;
76 unsigned s[] = {10000, 50000, 100000, 500000};
77 vector<unsigned> sizes(s, s+sizeof(s)/sizeof(*s));
79 vector<double> times_insert, times_find, times_erase;
81 for (vector<unsigned>::const_iterator i = sizes.begin(); i != sizes.end(); ++i) {
82 double time_insert, time_find, time_erase;
84 run_timing< exhashmap<ex> >(*i, time_insert, time_find, time_erase);
86 // If you like, you can compare it with this:
87 // run_timing< std::map<ex, ex, ex_is_less> >(*i, time_insert, time_find, time_erase);
89 times_insert.push_back(time_insert);
90 times_find.push_back(time_find);
91 times_erase.push_back(time_erase);
96 cout << endl << " size:\t";
97 copy(sizes.begin(), sizes.end(), ostream_iterator<unsigned>(cout, "\t"));
98 cout << endl << " insert/s:\t";
99 copy(times_insert.begin(), times_insert.end(), ostream_iterator<double>(cout, "\t"));
100 cout << endl << " find/s:\t";
101 copy(times_find.begin(), times_find.end(), ostream_iterator<double>(cout, "\t"));
102 cout << endl << " erase/s:\t";
103 copy(times_erase.begin(), times_erase.end(), ostream_iterator<double>(cout, "\t"));
109 extern void randomify_symbol_serials();
111 int main(int argc, char** argv)
113 randomify_symbol_serials();
114 cout << setprecision(2) << showpoint;
115 return time_hashmap();