forked from snakster/cpp.react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBenchmarkGrid.h
More file actions
171 lines (127 loc) · 4.18 KB
/
BenchmarkGrid.h
File metadata and controls
171 lines (127 loc) · 4.18 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// Copyright Sebastian Jeckel 2017.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#pragma once
#if 0
#ifndef REACT_BENCHMARK_GRID_H
#define REACT_BENCHMARK_GRID_H
#include <functional>
#include <iostream>
#include <vector>
#include "tbb/tick_count.h"
#include "BenchmarkBase.h"
#include "react/state.h"
using namespace react;
///////////////////////////////////////////////////////////////////////////////////////////////////
/// GridGraphGenerator
///////////////////////////////////////////////////////////////////////////////////////////////////
template <typename T>
class GridGraphGenerator
{
public:
using SignalType = Signal<T, shared>;
using Func1T = std::function<T(T)>;
using Func2T = std::function<T(T, T)>;
using SignalVectType = std::vector<SignalType>;
SignalVectType inputSignals;
SignalVectType outputSignals;
Func1T function1;
Func2T function2;
std::vector<size_t> widths;
void Generate(const GroupBase& group)
{
assert(inputSignals.size() >= 1);
assert(widths.size() >= 1);
SignalVectType buf1 = std::move(inputSignals);
SignalVectType buf2;
SignalVectType* curBuf = &buf1;
SignalVectType* nextBuf = &buf2;
size_t curWidth = inputSignals.size();
size_t nodeCount = 1;
nodeCount += curWidth;
for (auto targetWidth : widths)
{
while (curWidth != targetWidth)
{
// Grow or shrink?
bool shouldGrow = targetWidth > curWidth;
auto l = curBuf->begin();
auto r = curBuf->begin();
if (r != curBuf->end())
++r;
if (shouldGrow)
{
auto s = SignalType{ group, function1, *l };
nextBuf->push_back(std::move(s));
}
while (r != curBuf->end())
{
auto s = SignalType{ group, function2, *l, *r };
nextBuf->push_back(std::move(s));
++nodeCount;
++l; ++r;
}
if (shouldGrow)
{
auto s = SignalType{ group, function1, *l };
nextBuf->push_back(std::move(s));
++nodeCount;
}
curBuf->clear();
// Swap buffer pointers
SignalVectType* t = curBuf;
curBuf = nextBuf;
nextBuf = t;
if (shouldGrow)
++curWidth;
else
--curWidth;
}
}
//printf ("NODE COUNT %d\n", nodeCount);
outputSignals.clear();
outputSignals.insert(outputSignals.begin(), curBuf->begin(), curBuf->end());
}
};
///////////////////////////////////////////////////////////////////////////////////////////////////
/// Benchmark_Grid
///////////////////////////////////////////////////////////////////////////////////////////////////
struct BenchmarkParams_Grid
{
BenchmarkParams_Grid(int n, int k) :
N(n),
K(k)
{}
void Print(std::ostream& out) const
{
out << "N = " << N
<< ", K = " << K;
}
const int N;
const int K;
};
struct Benchmark_Grid
{
double Run(const BenchmarkParams_Grid& params, const GroupBase& group)
{
VarSignal<int, shared> in{ group, 1 };
Signal<int, shared> in2 = in;
GridGraphGenerator<int> generator;
generator.inputSignals.push_back(in2);
generator.widths.push_back(params.N);
generator.widths.push_back(1);
generator.function1 = [] (int a) { return a; };
generator.function2 = [] (int a, int b) { return a + b; };
generator.Generate(group);
auto t0 = tbb::tick_count::now();
for (int i=0; i<params.K; i++)
in <<= 10+i;
auto t1 = tbb::tick_count::now();
double d = (t1 - t0).seconds();
//printf("Time %g\n", d);
return d;
}
};
#endif // REACT_BENCHMARK_GRID_H
#endif