Created
June 3, 2009 00:31
-
-
Save diwakergupta/122708 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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