Skip to content

Instantly share code, notes, and snippets.

@mini3d
Created January 26, 2014 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mini3d/8626463 to your computer and use it in GitHub Desktop.
Save mini3d/8626463 to your computer and use it in GitHub Desktop.
// Distributed as Public Domain
#include <ctime>
#include <string>
#include <iostream>
typedef unsigned long ulong;
using namespace std;
struct Experiment {
virtual void Run() = 0;
void Benchmark(string name) {
clock_t s = clock();
Run();
s = clock() - s;
cout << name << ": " << (double)s / CLOCKS_PER_SEC << endl;
}
};
struct SampleExperiment : Experiment {
SampleExperiment() { /* setup code goes here */ }
~SampleExperiment() { /* teardown code goes here */ }
void Run() { cout << "Benchmark code goes here" << endl; }
};
int main(int argc, char **argv, char **arge) {
SampleExperiment().Benchmark("Sample");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment