/
main.cc
48 lines (37 loc) · 1.16 KB
/
main.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <cstdio>
#include <thread>
#include "ab_test.h"
using namespace std;
int diffs = 0;
void runSimulations(int sims, double a, double b, int requiredN) {
for(int i = 0; i < sims; i++) {
ABTest ab = ABTest(a, b, requiredN);
while (ab.next()) {}
if(ab.pValue() < 0.05) {
diffs++;
}
}
}
void simulate(string label, int totalSims, double a, double b, int requiredN) {
diffs = 0;
int numThreads = thread::hardware_concurrency();
thread threads[numThreads];
int simsPerThread = totalSims / thread::hardware_concurrency();
for(int i = 0; i < numThreads; i++) {
threads[i] = thread(runSimulations, simsPerThread, a, b, requiredN);
}
for(int i = 0; i < numThreads; i++) {
threads[i].join();
}
printf("%s: %.2f%%\n", label.c_str(), 100.0 *double(diffs) / double(numThreads*simsPerThread));
}
int main() {
int totalSims = 10000;
double mde = 0.05;
double a = 0.2;
double b = a * (1+mde);
int requiredN = 25580;
simulate("false positive rate", totalSims, a, a, requiredN);
simulate("true positive rate", totalSims, a, b, requiredN);
return 0;
}