-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmain.cpp
107 lines (91 loc) · 4.35 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "JobSystem.h"
#include <iostream>
#include <chrono>
#include <string>
using namespace std;
void Spin(float milliseconds)
{
milliseconds /= 1000.0f;
chrono::high_resolution_clock::time_point t1 = chrono::high_resolution_clock::now();
double ms = 0;
while (ms < milliseconds)
{
chrono::high_resolution_clock::time_point t2 = chrono::high_resolution_clock::now();
chrono::duration<double> time_span = chrono::duration_cast<chrono::duration<double>>(t2 - t1);
ms = time_span.count();
}
}
struct timer
{
string name;
chrono::high_resolution_clock::time_point start;
timer(const string& name) : name(name), start(chrono::high_resolution_clock::now()) {}
~timer()
{
auto end = chrono::high_resolution_clock::now();
cout << name << ": " << chrono::duration_cast<chrono::milliseconds>(end - start).count() << " milliseconds" << endl;
}
};
int main(int argc, char**args)
{
JobSystem::Initialize();
// Serial test
{
auto t = timer("Serial test: ");
Spin(100);
Spin(100);
Spin(100);
Spin(100);
Spin(100);
Spin(100);
}
// Execute test
{
auto t = timer("Execute() test: ");
JobSystem::Execute([] { Spin(100); });
JobSystem::Execute([] { Spin(100); });
JobSystem::Execute([] { Spin(100); });
JobSystem::Execute([] { Spin(100); });
JobSystem::Execute([] { Spin(100); });
JobSystem::Execute([] { Spin(100); });
JobSystem::Wait();
}
struct Data
{
float m[16];
void Compute(uint32_t value)
{
for (int i = 0; i < 16; ++i)
{
m[i] += float(value + i);
}
}
};
uint32_t dataCount = atoi(args[1]);
// Loop test:
{
Data* dataSet = new Data[dataCount];
{
auto t = timer("loop test: ");
for (uint32_t i = 0; i < dataCount; ++i)
{
dataSet[i].Compute(i);
}
}
delete[] dataSet;
}
// Dispatch test:
{
Data* dataSet = new Data[dataCount];
{
auto t = timer("Dispatch() test: ");
const uint32_t groupSize = 10000;
JobSystem::Dispatch(dataCount, groupSize, [&dataSet](JobDispatchArgs args) {
dataSet[args.jobIndex].Compute(1);
});
JobSystem::Wait();
}
delete[] dataSet;
}
return 0;
}