1 #ifndef SORTINGBENCHMARK_H 2 #define SORTINGBENCHMARK_H 57 void generate(
int* arr,
int n) {
58 for (
int i = 0; i < n; i++) {
59 arr[i] = ((double)rand()) / RAND_MAX * (2 * n);
63 bool check (
int* arr,
int n) {
65 for (
int i = 1; i < n; ++i) {
66 if (arr[i] < arr[i - 1]) {
85 time_cap = std::numeric_limits<double>::max();
137 setBaseSize (baseSize);
138 setMaxSize (maxSize);
139 setIncrement ((maxSize - baseSize) / nbPoint);
156 setBaseSize (baseSize);
157 setMaxSize (maxSize);
161 std::cerr <<
"base should be > 1.0\n";
184 void run(std::string algoName,
void (*runnable)(
int*,
int)) {
185 std::vector<double> time;
186 std::vector<double> xData;
191 for (
int n = baseSize; n <= maxSize;
192 n = std::max((
int)(geoBase * n) + increment, n + 1)) {
195 std::vector<int> arr(n);
197 generate(&arr[0], n);
199 std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();
201 runnable(&arr[0], n);
203 std::chrono::time_point<std::chrono::system_clock> end = std::chrono::system_clock::now();
205 std::chrono::duration<double> elapsed_seconds = end - start;
207 if (! check(&arr[0], n)) {
208 std::cerr <<
"Sorting algorithm " << algoName <<
" is incorrect\n";
211 time.push_back ((
double)elapsed_seconds.count() );
212 xData.push_back ( (
double)n );
214 if (elapsed_seconds.count() > time_cap) {
void setXLabel(string xaxisName)
Change the label for the X-axis.
Definition: LineChart.h:184
void setTimeCap(double cap_in_s)
sets an upper bound to the time of a run.
Definition: SortingBenchmark.h:174
void setGeometric(double base)
Sets a geometric progression for the benchmark size.
Definition: SortingBenchmark.h:121
void geometricRange(int baseSize, int maxSize, double base)
The benchmark will sample a range using in geometrically increasing sequence.
Definition: SortingBenchmark.h:155
Show series of data or functions using a line chart.
Definition: LineChart.h:43
Benchmarks sorting algorithm.
Definition: SortingBenchmark.h:47
void setXData(string series, vector< double > xdata)
Changes the X data for a series.
Definition: LineChart.h:217
void setMaxSize(int size)
Puts a cap on the largest array to be used.
Definition: SortingBenchmark.h:93
void setBaseSize(int size)
Smallest array to be used.
Definition: SortingBenchmark.h:102
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
void run(std::string algoName, void(*runnable)(int *, int))
benchmark one implementation
Definition: SortingBenchmark.h:184
void linearRange(int baseSize, int maxSize, int nbPoint)
The benchmark will sample a range with a fixed number of points.
Definition: SortingBenchmark.h:136
void setIncrement(int inc)
Sets the increment for the benchmark size.
Definition: SortingBenchmark.h:112
SortingBenchmark(LineChart &p)
Definition: SortingBenchmark.h:74
void setYData(string series, vector< double > ydata)
Changes the Y data for a series.
Definition: LineChart.h:237
void setYLabel(string yaxisName)
Change the label for the Y-axis.
Definition: LineChart.h:166