benchmark silo added
[c11concurrency-benchmarks.git] / silo / masstree / testrunner.cc
1 /* Masstree
2  * Eddie Kohler, Yandong Mao, Robert Morris
3  * Copyright (c) 2012-2013 President and Fellows of Harvard College
4  * Copyright (c) 2012-2013 Massachusetts Institute of Technology
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, subject to the conditions
9  * listed in the Masstree LICENSE file. These conditions include: you must
10  * preserve this copyright notice, and you cannot mention the copyright
11  * holders in advertising related to the Software without their permission.
12  * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
13  * notice is a summary of the Masstree LICENSE file; the license in that file
14  * is legally binding.
15  */
16 #include "testrunner.hh"
17 #include <algorithm>
18 #include <numeric>
19 #include <vector>
20
21 testrunner_base* testrunner_base::thehead;
22 testrunner_base* testrunner_base::thetail;
23
24 void testrunner_base::print_names(FILE* stream, int ncol) {
25     masstree_precondition(ncol >= 1);
26
27     std::vector<lcdf::String> names;
28     for (testrunner_base* tr = thehead; tr; tr = tr->next_)
29         names.push_back(tr->name());
30
31     size_t percol;
32     std::vector<int> colwidth;
33     while (1) {
34         percol = (names.size() + ncol - 1) / ncol;
35         colwidth.assign(ncol, 0);
36         for (size_t i = 0; i != names.size(); ++i)
37             colwidth[i/percol] = std::max(colwidth[i/percol], names[i].length());
38         if (ncol == 1
39             || std::accumulate(colwidth.begin(), colwidth.end(), 0)
40                + ncol * 3 <= 78)
41             break;
42         --ncol;
43     }
44
45     for (size_t row = 0; row != percol; ++row) {
46         size_t off = row;
47         for (int col = 0; col != ncol; ++col, off += percol)
48             if (off < names.size())
49                 fprintf(stream, "%*s   %s",
50                         col ? colwidth[col-1] - names[off-percol].length() : 0, "",
51                         names[off].c_str());
52         fprintf(stream, "\n");
53     }
54 }