Skip to content

Instantly share code, notes, and snippets.

@diwakergupta
Created June 3, 2009 00:31
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 diwakergupta/122708 to your computer and use it in GitHub Desktop.
Save diwakergupta/122708 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
struct AllocationItem {
int value;
AllocationItem(int v) : value(v) {}
};
void RunAllocations(int iters) {
int sum = 0;
for (int i = 0; i < iters; ++i) {
AllocationItem* item = new AllocationItem(i);
sum += item->value;
delete item;
}
cout << "Ran " << iters << " allocations of RunAllocations. "
<< "Final value: " << sum << endl;
}
int main(int argc, char** argv) {
if (argc < 3) {
cerr << "Bad commandline" << endl;
return 1;
}
char* benchmark = argv[1];
int iters = strtol(argv[2], NULL, 10);
if (strcmp(benchmark, "allocations") == 0) {
RunAllocations(iters);
} else {
cerr << "Invalid benchmark name" << endl;
return 2;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment