1 /** @file time_hashmap.cpp
3 * Timings for exhashmap<> operations. */
6 * GiNaC Copyright (C) 1999-2009 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
25 using namespace GiNaC;
32 static void run_timing(unsigned size, double &time_insert, double &time_find, double &time_erase)
39 for (unsigned i=0; i<size; ++i)
40 S.push_back(symbol());
43 for (unsigned i=0; i<size; ++i)
44 M[S[i]] = S[(i+1)%size];
45 time_insert = t.read();
48 for (unsigned i=0; i<size; ++i) {
49 if (!M[S[i]].is_equal(S[(i+1)%size])) {
50 clog << "map lookup failed" << endl;
57 for (unsigned i=0; i<size; ++i) {
58 if (M.erase(S[i]) != 1) {
59 clog << "erasing element " << S[i] << " failed" << endl;
64 clog << "map not empty (size = " << M.size() << ") after erasing all elements" << endl;
67 time_erase = t.read();
71 unsigned time_hashmap()
75 cout << "timing hash map operations" << flush;
77 unsigned s[] = {10000, 50000, 100000, 500000};
78 vector<unsigned> sizes(s, s+sizeof(s)/sizeof(*s));
80 vector<double> times_insert, times_find, times_erase;
82 for (vector<unsigned>::const_iterator i = sizes.begin(); i != sizes.end(); ++i) {
83 double time_insert, time_find, time_erase;
85 run_timing< exhashmap<ex> >(*i, time_insert, time_find, time_erase);
87 // If you like, you can compare it with this:
88 // run_timing< std::map<ex, ex, ex_is_less> >(*i, time_insert, time_find, time_erase);
90 times_insert.push_back(time_insert);
91 times_find.push_back(time_find);
92 times_erase.push_back(time_erase);
97 cout << endl << " size:\t";
98 copy(sizes.begin(), sizes.end(), ostream_iterator<unsigned>(cout, "\t"));
99 cout << endl << " insert/s:\t";
100 copy(times_insert.begin(), times_insert.end(), ostream_iterator<double>(cout, "\t"));
101 cout << endl << " find/s:\t";
102 copy(times_find.begin(), times_find.end(), ostream_iterator<double>(cout, "\t"));
103 cout << endl << " erase/s:\t";
104 copy(times_erase.begin(), times_erase.end(), ostream_iterator<double>(cout, "\t"));
110 extern void randomify_symbol_serials();
112 int main(int argc, char** argv)
114 randomify_symbol_serials();
115 cout << setprecision(2) << showpoint;
116 return time_hashmap();