forked from xuyangm/CBlockSim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
executable file
·32 lines (30 loc) · 989 Bytes
/
Main.cpp
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
#include <iostream>
#include <ctime>
#include "Scheduler.h"
using namespace std;
int main()
{
double rate = 0, half = 0, ninety = 0;
for(int rd = 0; rd < ROUND; rd++) {
clock_t end = clock();
int num = 0;
double globalTime = 0;
Scheduler* scheduler = new Scheduler();
scheduler->GenerateInitialEvents();
while (!scheduler->evEngine.IsEmpty() && globalTime <= SIM_TIME) {
auto nextEvent = scheduler->evEngine.GetEvent();
globalTime = nextEvent->timestamp;
if (nextEvent->type == GENERATE_BLOCK) {
num++;
cout << "GENERATE " << num << " BLOCKS, CLOCK: " << globalTime << ", AVERAGE BLOCK TIME: " << (double)globalTime / num << " s" << endl;
}
scheduler->HandleEvent(nextEvent);
scheduler->evEngine.RemoveEvent(nextEvent);
}
scheduler->ResolveFork();
scheduler->DistributeRewards();
rate += scheduler->ShowStatistics(rd+1, (double)(clock() - end) / CLOCKS_PER_SEC / 60);
delete scheduler;
}
return 0;
}