81int main(
int argc,
char* argv[]) {
84 int totalTrials = 100'000'000;
85 std::string method =
"All";
87 if (argc > 1) totalTrials = std::atoi(argv[1]);
88 if (argc > 2) method = argv[2];
90 std::unordered_set<std::string> validMethods = {
91 "Sequential",
"Heap",
"Pool",
"SIMD",
"All"
93 if (!validMethods.count(method)) {
94 std::cerr <<
"[ERROR] Unknown method: " << method <<
"\n";
95 std::cerr <<
"Valid options: Sequential, Heap, Pool, SIMD, All\n";
101 if (method ==
"Sequential" || method ==
"All") {
102 benchmark(
"Sequential", totalTrials, [&]() {
107 if (method ==
"Heap" || method ==
"All") {
108 benchmark(
"Heap (Threaded)", totalTrials, [&]() {
109 std::vector<std::thread> threads;
110 std::vector<int*> results(threadCount);
111 int perThread = totalTrials / threadCount;
113 for (
int t = 0; t < threadCount; ++t) {
114 threads.emplace_back([&, t]() {
119 for (
auto& th : threads) th.join();
122 for (
auto ptr : results) {
132 if (method ==
"Pool" || method ==
"All") {
133 benchmark(
"Pool (Threaded)", totalTrials, [&]() {
134 std::vector<std::thread> threads;
135 std::vector<int*> results(threadCount);
136 int perThread = totalTrials / threadCount;
138 for (
int t = 0; t < threadCount; ++t) {
139 threads.emplace_back([&, t]() {
144 for (
auto& th : threads) th.join();
147 for (
auto ptr : results) {
156 if (method ==
"SIMD" || method ==
"All") {
157 benchmark(
"SIMD (Threaded)", totalTrials, [&]() {
158 std::vector<std::thread> threads;
159 std::vector<int*> results(threadCount);
160 int perThread = totalTrials / threadCount;
162 for (
int t = 0; t < threadCount; ++t) {
163 threads.emplace_back([&, t]() {
168 for (
auto& th : threads) th.join();
171 for (
auto ptr : results) {
void benchmark(const std::string &name, int trials, std::function< int()> func)
Benchmark wrapper that logs wall time and CPU cycles.
int main(int argc, char *argv[])
Entry point for running Monte Carlo simulations via CLI.
void print_arch_info()
Prints detected platform architecture and SIMD capability.