performance testing facility
/*
* Created by CrazyPython.
* Licensed under CC Attribution 4.0 International
* License text at https://creativecommons.org/licenses/by/4.0/
*/
#include <ctime>
#include <iostream>
#include <ctype.h>
#include <algorithm>
#include <vector>
#include <sstream>
/* Often-used libraries */
using namespace std;
void inline task2() {
}
void inline task1() {
}
void initialize() {
}
double iterations = 1000000; // Number of iterations per test
double testcount = 4; // Number of independent tests to perform
int main() {
cout << "Timer starting..." << endl;
for (int j = 1; j < testcount + 1; ++j) {
cout << "Run #" << j << ':' << endl;
initialize();
double start = (double) time(nullptr);
for (int i = 0; i < iterations + 1; ++i) {
task1();
}
double stop = (double) time(nullptr);
double time1 = stop - start;
double time1microseconds = ((stop - start) / iterations) * 1000000;
cout << "\tTask 1: " << stop - start << " / " << iterations << " = " << time1microseconds
<< " microseconds" << endl;
start = (double) time(nullptr);
for (int i = 0; i < iterations + 1; ++i) {
task2();
}
stop = (double) time(nullptr);
double time2 = stop - start;
double time2microseconds = ((stop - start) / iterations) * 1000000;
cout << "\tTask 2: " << stop - start << " / " << iterations << " = " << time2microseconds
<< " microseconds" << endl;
if (time2 > time1) {
cout << "\tTask 1 was " << (int) time2 / time1 << "x times faster by "
<< time2microseconds - time1microseconds
<< " microseconds" << endl;
} else if (time2 < time1) {
cout << "\tTask 2 was " << (int) time1 / time2 << "x times faster by "
<< time1microseconds - time2microseconds
<< " microseconds" << endl;
} else {
cout << "\tNeither task was faster." << endl;
}
}
}