forked from snakster/cpp.react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBenchmarkFanout.h
More file actions
86 lines (66 loc) · 2.02 KB
/
BenchmarkFanout.h
File metadata and controls
86 lines (66 loc) · 2.02 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
// Copyright Sebastian Jeckel 2014.
// 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
#ifndef CPP_REACT_BENCHMARK_FANOUT_H
#define CPP_REACT_BENCHMARK_FANOUT_H
#include <iostream>
#include <random>
#include <vector>
#include "BenchmarkBase.h"
#include "react/Signal.h"
using namespace react;
///////////////////////////////////////////////////////////////////////////////////////////////////
/// Benchmark_Fanout
///////////////////////////////////////////////////////////////////////////////////////////////////
struct BenchmarkParams_Fanout
{
BenchmarkParams_Fanout(int n, int k, int delay) :
N(n),
K(k),
Delay(delay)
{}
void Print(std::ostream& out) const
{
out << "N = " << N
<< ", K = " << K
<< ", Delay = " << Delay;
}
const int N;
const int K;
const int Delay;
};
template <typename D>
struct Benchmark_Fanout : public BenchmarkBase<D>
{
double Run(const BenchmarkParams_Fanout& params)
{
using MySignal = Signal<D,int>;
bool initializing = true;
auto in = MakeVar<D>(1);
std::vector<MySignal> nodes;
auto f = [&initializing,¶ms] (int a)
{
if (params.Delay > 0 && !initializing)
{
auto t0 = std::chrono::high_resolution_clock::now();
while (std::chrono::high_resolution_clock::now() - t0 < std::chrono::milliseconds(params.Delay));
}
return a + 1;
};
for (int i=0; i<params.N; i++)
{
auto t = MakeSignal(in, f);
nodes.push_back(t);
}
initializing = false;
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();
return d;
}
};
#endif // CPP_REACT_BENCHMARK_FANOUT_H