Skip to content

Commit f206f7b

Browse files
committed
feat: more benchmarks
1 parent 437985e commit f206f7b

File tree

7 files changed

+192
-35
lines changed

7 files changed

+192
-35
lines changed

Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
FROM ubuntu:23.10
22

33
RUN apt-get update
4-
RUN apt-get -y install python3.12 python3.12-venv python3.12-dev cmake build-essential cmake build-essential valgrind python3.12-dbg
4+
RUN apt-get -y install python3.12 python3.12-venv python3.12-dev build-essential
55

66
WORKDIR app
77

88
COPY . .
99

1010
RUN python3.12 -m venv .venv
11-
12-
#RUN source .venv/bin/activate && pip install setuptools
13-
#RUN source .venv/bin/activate && python3 setup.py install
11+
#RUN source .venv/bin/activate && python3.12 -m pip install .

thesis/bench.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@
284284
"name": "python",
285285
"nbconvert_exporter": "python",
286286
"pygments_lexer": "ipython3",
287-
"version": "3.11.9"
287+
"version": "3.11.4"
288288
}
289289
},
290290
"nbformat": 4,

thesis/bench_many_ms.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@
242242
"name": "python",
243243
"nbconvert_exporter": "python",
244244
"pygments_lexer": "ipython3",
245-
"version": "3.11.9"
245+
"version": "3.11.4"
246246
}
247247
},
248248
"nbformat": 4,

thesis/comparison.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import multiprocessing
2+
from fastflow import FFPipeline, ff_send_out
3+
4+
# Stage 1: Generate numbers from 1 to 10
5+
def number_generator(pipe_out):
6+
counter = 1
7+
while counter <= 10:
8+
pipe_out.send(counter)
9+
counter += 1
10+
pipe_out.close()
11+
12+
# Stage 2: Square each number
13+
def square_node(pipe_in, pipe_out):
14+
while True:
15+
try:
16+
data = pipe_in.recv()
17+
pipe_out.send(data*data)
18+
except EOFError:
19+
pipe_out.close()
20+
break
21+
22+
# Stage 3: Square each number
23+
def subtract_five_node(pipe_in, pipe_out):
24+
while True:
25+
try:
26+
data = pipe_in.recv()
27+
pipe_out.send(data-5)
28+
except EOFError:
29+
pipe_out.close()
30+
break
31+
32+
# Create the pipes
33+
pipe1_out, pipe1_in = multiprocessing.Pipe(duplex=False)
34+
pipe2_out, pipe2_in = multiprocessing.Pipe(duplex=False)
35+
36+
# Create the processes
37+
processes = [
38+
multiprocessing.Process(target=number_generator, args=(pipe1_in)),
39+
multiprocessing.Process(target=square_node, args=(pipe1_out, pipe2_in)),
40+
multiprocessing.Process(target=subtract_five_node, args=(pipe2_out, None))
41+
]
42+
43+
# Start all processes in the pipeline
44+
for process in processes:
45+
process.start()
46+
47+
# Wait for all processes to finish
48+
for process in processes:
49+
process.join()
50+
51+
52+
class NumberGenerator():
53+
def svc(self):
54+
for i in range(1, 11):
55+
ff_send_out(i)
56+
return EOS
57+
58+
class SquareNode():
59+
def svc(self, number):
60+
return number * number
61+
62+
class SubtractFiveNode():
63+
def svc(self, number):
64+
return number - 5
65+
66+
# Build the pipeline and add the stages
67+
pipe = FFPipeline()
68+
pipe.add_stage(NumberGenerator())
69+
pipe.add_stage(SquareNode())
70+
pipe.add_stage(SubtractFiveNode())
71+
72+
# Run the pipeline
73+
if pipe.run_and_wait_end() < 0:
74+
# handle error...

thesis/example.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <iostream>
2+
#include <ff/ff.hpp>
3+
4+
// Stage 1: Generate numbers from 1 to 10
5+
struct NumberGenerator : ff::ff_node_t<int> {
6+
int* svc(int*) {
7+
for (int i = 1; i <= 10; ++i) {
8+
ff_send_out(new int(i)); // Send numbers 1 to 10
9+
}
10+
return (int*) ff::FF_EOS; // End of stream
11+
}
12+
};
13+
14+
// Stage 2: Square each number
15+
struct SquareNode : ff::ff_node_t<int> {
16+
int* svc(int* number) {
17+
int* result = new int((*number) * (*number));
18+
delete number;
19+
return result;
20+
}
21+
};
22+
23+
// Stage 3: Subtract 5 from each squared number
24+
struct SubtractFiveNode : ff::ff_node_t<int> {
25+
int* svc(int* squared_number) {
26+
int* result = new int((*squared_number) - 5);
27+
delete squared_number;
28+
return result;
29+
}
30+
};
31+
32+
// Build the pipeline and add the stages
33+
auto pipe = new ff::ff_pipeline();
34+
pipe->add_stage(new NumberGenerator());
35+
pipe->add_stage(new SquareNode());
36+
pipe->add_stage(new SubtractFiveNode());
37+
38+
// Run the pipeline
39+
if (pipe->run_and_wait_end() < 0) {
40+
/* handle error... */
41+
return -1;
42+
}

thesis/zerodivision.ipynb

Lines changed: 72 additions & 29 deletions
Large diffs are not rendered by default.

thesis/zerodivision.png

-121 KB
Loading

0 commit comments

Comments
 (0)