Skip to content

Commit fef6d1c

Browse files
author
Ivan Le Lann
committed
cleanups
1 parent 1f6ddb7 commit fef6d1c

41 files changed

Lines changed: 172 additions & 2794 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CMakeLists.txt‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Configuration
22
cmake_minimum_required (VERSION 2.6)
3+
enable_testing()
34

45
project (CppReact)
56

@@ -12,12 +13,15 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wpedantic")
1213
include_directories ("${PROJECT_SOURCE_DIR}/include")
1314

1415
### CppReact
16+
file(GLOB_RECURSE CPPREACT_HEADERS include/*.h)
17+
1518
add_library(CppReact
1619
src/engine/PulsecountEngine.cpp
1720
src/engine/SubtreeEngine.cpp
1821
src/engine/ToposortEngine.cpp
1922
src/logging/EventLog.cpp
20-
src/logging/EventRecords.cpp)
23+
src/logging/EventRecords.cpp
24+
${CPPREACT_HEADERS})
2125

2226
target_link_libraries(CppReact tbb)
2327

@@ -28,13 +32,13 @@ if(build_examples)
2832
endif()
2933

3034
### benchmarks/
31-
option(build_benchmarks "Build benchmarks?" OFF)
35+
option(build_benchmarks "Build benchmarks?" ON)
3236
if(build_benchmarks)
3337
add_subdirectory(benchmarks)
3438
endif()
3539

3640
### tests/
37-
option(build_tests "Build unit tests?" OFF)
41+
option(build_tests "Build unit tests?" ON)
3842
if(build_tests)
3943
add_subdirectory(tests)
4044
endif()

‎benchmarks/CMakeLists.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
add_executable(CppReactBenchmark src/Main.cpp)
44
target_link_libraries(CppReactBenchmark CppReact tbbmalloc_proxy)
5+
6+
add_test(NAME CppReactBenchmark COMMAND CppReactBenchmark "-r" CONFIGURATIONS Benchmark)

‎benchmarks/src/BenchmarkBase.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
// Get unique random numbers from range.
2121
///////////////////////////////////////////////////////////////////////////////////////////////////
2222
template <typename T, typename TGen>
23-
const std::vector<T> GetUniqueRandomNumbers(TGen gen, T from, T to, int count)
23+
const std::vector<T> GetUniqueRandomNumbers(TGen gen, T from, T to, T count)
2424
{
2525
std::vector<T> data(1 + to - from);
2626
int c = from;
2727
for (auto& p : data)
2828
p = c++;
2929

30-
for (int i=0; i<count; i++)
30+
for (T i=0; i<count; i++)
3131
{
3232
std::uniform_int_distribution<T> dist(i,(to - from));
3333
auto r = dist(gen);

‎benchmarks/src/BenchmarkRandom.h‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ class RandomGraphGenerator
5353
Func3T Function3;
5454
Func4T Function4;
5555

56-
int Width = 1;
57-
int Height = 1;
56+
unsigned int Width = 1;
57+
unsigned int Height = 1;
5858

59-
int SelectSlowCount = 0;
60-
int SelectEdgeCount = 0;
59+
unsigned int SelectSlowCount = 0;
60+
unsigned int SelectEdgeCount = 0;
6161

62-
int EdgeSeed;
63-
int SlowSeed;
62+
unsigned int EdgeSeed;
63+
unsigned int SlowSeed;
6464

6565
void Generate()
6666
{
@@ -76,7 +76,7 @@ class RandomGraphGenerator
7676
Func3T f3Fast = [this] (TValue a1, TValue a2, TValue a3) { FastDelayFunc(); return Function3(a1,a2,a3); };
7777
Func4T f4Fast = [this] (TValue a1, TValue a2, TValue a3, TValue a4) { FastDelayFunc(); return Function4(a1,a2,a3,a4); };
7878

79-
int nodeCount = Width * Height;
79+
auto nodeCount = Width * Height;
8080

8181
std::mt19937 edgeGen(EdgeSeed);
8282
const auto edgeNodes = GetUniqueRandomNumbers(edgeGen, Width, nodeCount - 1, SelectEdgeCount);
@@ -90,17 +90,17 @@ class RandomGraphGenerator
9090
auto edgeNodeIt = edgeNodes.begin();
9191
auto slowNodeIt = slowNodes.begin();
9292

93-
auto cur = 0;
93+
unsigned cur = 0;
9494
HandleVect nodes(nodeCount);
9595

96-
for (int w=0; w<Width; w++)
96+
for (unsigned w=0; w<Width; w++)
9797
nodes[cur++] = InputSignals[w];
9898

99-
for (int h=1; h<Height; h++)
99+
for (unsigned h=1; h<Height; h++)
100100
{
101101
std::uniform_int_distribution<int> nodeDist(0, Width*h - 1);
102102

103-
for (int w=0; w<Width; w++)
103+
for (unsigned w=0; w<Width; w++)
104104
{
105105
Func1T f1 = f1Fast;
106106
Func2T f2 = f2Fast;
@@ -165,7 +165,7 @@ class RandomGraphGenerator
165165
}
166166

167167
OutputSignals.clear();
168-
for (int i=Width*(Height-1); i<nodeCount; i++)
168+
for (unsigned i=Width*(Height-1); i<nodeCount; i++)
169169
OutputSignals.push_back(nodes[i]);
170170
}
171171
};
@@ -321,4 +321,4 @@ struct Benchmark_Random : public BenchmarkBase<D>
321321

322322
return d;
323323
}
324-
};
324+
};

‎benchmarks/src/Main.cpp‎

Lines changed: 68 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ void runBenchmarkRandom(std::ostream& out)
8181

8282
void runBenchmarkFanout(std::ostream& out)
8383
{
84-
//RUN_BENCHMARK(out, 5, Benchmark_Fanout, BenchmarkParams_Fanout(10, 10000, 0),
85-
// ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain);
84+
RUN_BENCHMARK(out, 5, Benchmark_Fanout, BenchmarkParams_Fanout(10, 10000, 0),
85+
ToposortSTDomain, ToposortDomain, PulsecountDomain);
8686

87-
//RUN_BENCHMARK(out, 5, Benchmark_Fanout, BenchmarkParams_Fanout(100, 10000, 0),
88-
// ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain);
87+
RUN_BENCHMARK(out, 5, Benchmark_Fanout, BenchmarkParams_Fanout(100, 10000, 0),
88+
ToposortSTDomain, ToposortDomain, PulsecountDomain);
8989

90-
//RUN_BENCHMARK(out, 5, Benchmark_Fanout, BenchmarkParams_Fanout(1000, 10000, 0),
91-
// ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain);
90+
RUN_BENCHMARK(out, 5, Benchmark_Fanout, BenchmarkParams_Fanout(1000, 10000, 0),
91+
ToposortSTDomain, ToposortDomain, PulsecountDomain);
9292

9393
RUN_BENCHMARK(out, 3, Benchmark_Fanout, BenchmarkParams_Fanout(10, 10, 10),
9494
ToposortSTDomain, ToposortDomain, PulsecountDomain);
@@ -100,41 +100,41 @@ void runBenchmarkFanout(std::ostream& out)
100100
ToposortSTDomain, ToposortDomain, PulsecountDomain);
101101
}
102102

103-
void runBenchmarkSequence(std::ostream& out)
104-
{
105-
//RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(10, 10000, 0),
106-
// ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain);
103+
//void runBenchmarkSequence(std::ostream& out)
104+
//{
105+
// //RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(10, 10000, 0),
106+
// // ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain);
107107

108-
//RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(100, 10000, 0),
109-
// ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain);
108+
// //RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(100, 10000, 0),
109+
// // ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain);
110110

111-
//RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(1000, 10000, 0),
112-
// ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain);
111+
// //RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(1000, 10000, 0),
112+
// // ToposortSTDomain, ToposortDomain, ELMDomain, PulsecountDomain, SourceSetDomain);
113113

114-
RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(10, 10, 10),
115-
ToposortSTDomain, ToposortDomain, PulsecountDomain);
114+
// RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(10, 10, 10),
115+
// ToposortSTDomain, ToposortDomain, PulsecountDomain);
116116

117-
RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(100, 10, 10),
118-
ToposortSTDomain, ToposortDomain, PulsecountDomain);
117+
// RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(100, 10, 10),
118+
// ToposortSTDomain, ToposortDomain, PulsecountDomain);
119119

120-
RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(1000, 10, 10),
121-
ToposortSTDomain, ToposortDomain, PulsecountDomain);
122-
}
120+
// RUN_BENCHMARK(out, 3, Benchmark_Sequence, BenchmarkParams_Sequence(1000, 10, 10),
121+
// ToposortSTDomain, ToposortDomain, PulsecountDomain);
122+
//}
123123

124-
void runBenchmarkLifeSim(std::ostream& out)
125-
{
126-
//RUN_BENCHMARK(std::cout, 1, Benchmark_LifeSim, BenchmarkParams_LifeSim(150, 1000),
127-
// ELMDomain);
124+
//void runBenchmarkLifeSim(std::ostream& out)
125+
//{
126+
// //RUN_BENCHMARK(std::cout, 1, Benchmark_LifeSim, BenchmarkParams_LifeSim(150, 10, 1000),
127+
// // ToposortDomain);
128128

129-
//RUN_BENCHMARK(std::cout, 1, Benchmark_LifeSim, BenchmarkParams_LifeSim(250, 30, 10000),
130-
// SourceSetDomain, PulsecountDomain);
129+
// //RUN_BENCHMARK(std::cout, 1, Benchmark_LifeSim, BenchmarkParams_LifeSim(250, 30, 10000),
130+
// // SourceSetDomain, PulsecountDomain);
131131

132-
RUN_BENCHMARK(out, 1, Benchmark_LifeSim, BenchmarkParams_LifeSim(100, 15, 10000),
133-
ToposortSTDomain, ToposortDomain, PulsecountDomain);
132+
// //RUN_BENCHMARK(out, 1, Benchmark_LifeSim, BenchmarkParams_LifeSim(100, 15, 10000),
133+
// //ToposortSTDomain, ToposortDomain, PulsecountDomain);
134134

135-
//RUN_BENCHMARK(out, 3, Benchmark_LifeSim, BenchmarkParams_LifeSim(100, 50, 100),
136-
// PulsecountDomain, PulsecountDomain);
137-
}
135+
// //RUN_BENCHMARK(out, 3, Benchmark_LifeSim, BenchmarkParams_LifeSim(100, 50, 100),
136+
// // PulsecountDomain, PulsecountDomain);
137+
//}
138138

139139
void runBenchmarks()
140140
{
@@ -144,21 +144,21 @@ void runBenchmarks()
144144
logfile.open(path.c_str());
145145

146146
// === GRID
147-
//runBenchmarkGrid(logfile);
148-
149-
//runBenchmarkFlooding(logfile);
147+
runBenchmarkGrid(logfile);
150148

151149
// === RANDOM
152-
//runBenchmarkRandom(logfile);
150+
if (0)
151+
runBenchmarkRandom(logfile);
153152

154153
// === FANOUT
155-
//runBenchmarkFanout(logfile);
154+
if (0)
155+
runBenchmarkFanout(logfile);
156156

157157
// === SEQUENCE
158158
//runBenchmarkSequence(logfile);
159159

160160
// === LIFESIM
161-
runBenchmarkLifeSim(logfile);
161+
//runBenchmarkLifeSim(logfile);
162162

163163
logfile.close();
164164
}
@@ -233,9 +233,34 @@ void profileBenchmark()
233233

234234
} // ~anonymous namespace
235235

236-
int main()
236+
#include <algorithm>
237+
238+
int main(int argc, char * argv[])
237239
{
238-
//runBenchmarks();
239-
//debugBenchmarks();
240-
profileBenchmark();
241-
}
240+
auto begin = argv;
241+
auto end = argv + argc;
242+
243+
// auto getCmdOption = [&](const std::string & option) -> char*
244+
// {
245+
// char ** itr = std::find(begin, end, option);
246+
// if (itr != end && ++itr != end)
247+
// {
248+
// return *itr;
249+
// }
250+
// return 0;
251+
// };
252+
253+
auto cmdOptionExists = [&](const std::string& option) -> bool
254+
{
255+
return std::find(begin, end, option) != end;
256+
};
257+
258+
std::cout << "-d to debug, -p to profile. run by default" << std::endl;
259+
260+
if (cmdOptionExists("-d"))
261+
debugBenchmarks();
262+
else if (cmdOptionExists("-p"))
263+
profileBenchmark();
264+
else
265+
runBenchmarks();
266+
}

‎examples/src/BasicReactors.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace example1
3535

3636
ReactorT loop
3737
{
38-
[&] (ReactorT::Context ctx)
38+
[] (ReactorT::Context ctx)
3939
{
4040
PathT points;
4141

@@ -101,13 +101,13 @@ namespace example2
101101

102102
ReactorT loop
103103
{
104-
[&] (ReactorT::Context ctx)
104+
[] (ReactorT::Context ctx)
105105
{
106106
PathT points;
107107

108108
points.emplace_back(ctx.Await(mouseDown));
109109

110-
auto count = ctx.Get(counter);
110+
ctx.Get(counter);
111111

112112
ctx.RepeatUntil(mouseUp, [&] {
113113
points.emplace_back(ctx.Await(mouseMove));
@@ -158,4 +158,4 @@ int main()
158158
example2::Run();
159159

160160
return 0;
161-
}
161+
}

0 commit comments

Comments
 (0)