Skip to content

Commit 060c058

Browse files
authored
Merge pull request #31 from lf-lang/lf-ts
Utilize the BenchmarkRunner reactor & Add 'lf-ts' section in runner configuration
2 parents 9e6f04a + 2a41745 commit 060c058

File tree

8 files changed

+116
-88
lines changed

8 files changed

+116
-88
lines changed

TS/Savina/src/micro/Big.lf

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ target TypeScript {
88
fast: true
99
};
1010

11-
main reactor Big(limit:number(25000)) {
12-
13-
state startTime:time;
11+
import BenchmarkRunner from "../BenchmarkRunner.lf";
12+
13+
main reactor Big(numIterations:number(12), limit:number(25000)) {
14+
15+
runner = new BenchmarkRunner(numIterations = numIterations);
1416

1517
s = new Sink();
1618

@@ -19,6 +21,9 @@ main reactor Big(limit:number(25000)) {
1921
p3 = new PingPonger(limit = limit, index = 3);
2022
p4 = new PingPonger(limit = limit, index = 4);
2123
p5 = new PingPonger(limit = limit, index = 5);
24+
25+
(runner.start)+ -> p1.start, p2.start, p3.start, p4.start, p5.start;
26+
s.stopTimer -> runner.finish;
2227

2328
p1.done -> s.done1;
2429
p2.done -> s.done2;
@@ -75,30 +80,14 @@ main reactor Big(limit:number(25000)) {
7580
p5.respond2 -> p2.ack5;
7681
p5.respond3 -> p3.ack5;
7782
p5.respond4 -> p4.ack5;
78-
79-
reaction(startup) -> p1.start, p2.start, p3.start, p4.start, p5.start {=
80-
startTime = util.getCurrentPhysicalTime();
81-
p1.start = null;
82-
p2.start = null;
83-
p3.start = null;
84-
p4.start = null;
85-
p5.start = null;
86-
=}
87-
88-
reaction(s.stopTimer) {=
89-
if (startTime) {
90-
let elapsedTime = util.getCurrentPhysicalTime().subtract(startTime);
91-
console.log("Elapsed time: " + elapsedTime);
92-
util.requestStop();
93-
}
94-
=}
83+
9584
}
9685

9786

9887
// Index is the number of this ping ponger and must be set
9988
// to x with 1 <= x <= numberOfActors, when the instance is created.
10089
reactor PingPonger(limit:number(25000), index:number(-1), numberOfActors:number(5)) {
101-
input start:null;
90+
input start:boolean;
10291
output done:null;
10392
output send1:string;
10493
output send2:string;
@@ -134,61 +123,62 @@ reactor PingPonger(limit:number(25000), index:number(-1), numberOfActors:number(
134123
switch (sendIndex) {
135124
case 1: {
136125
send1 = "ping";
137-
// console.log(`In index: ${index}, pinging: 1 `);
126+
// console.log(`In index: ${index}, pinging: 1 `);
138127
break;
139128
}
140129
case 2: {
141130
send2 = "ping";
142-
// console.log(`In index: ${index}, pinging: 2 `);
131+
// console.log(`In index: ${index}, pinging: 2 `);
143132
break;
144133
}
145134
case 3: {
146135
send3 = "ping";
147-
// console.log(`In index: ${index}, pinging: 3 `);
136+
// console.log(`In index: ${index}, pinging: 3 `);
148137
break;
149138
}
150139
case 4: {
151140
send4 = "ping";
152-
// console.log(`In index: ${index}, pinging: 4 `);
141+
// console.log(`In index: ${index}, pinging: 4 `);
153142
break;
154143
}
155144
case 5: {
156145
send5 = "ping";
157-
// console.log(`In index: ${index}, pinging: 5 `);
146+
// console.log(`In index: ${index}, pinging: 5 `);
158147
break;
159148
}
160149
}
161150
=}
162151

163152
reaction (receive1) -> respond1 {=
164153
respond1 = "pong";
165-
// console.log(`In index: ${index}, ponging: 1 `);
154+
// console.log(`In index: ${index}, ponging: 1 `);
166155
=}
167156

168157
reaction (receive2) -> respond2 {=
169158
respond2 = "pong";
170-
// console.log(`In index: ${index}, ponging: 2 `);
159+
// console.log(`In index: ${index}, ponging: 2 `);
171160
=}
172161

173162
reaction (receive3) -> respond3 {=
174163
respond3 = "pong";
175-
// console.log(`In index: ${index}, ponging: 3 `);
164+
// console.log(`In index: ${index}, ponging: 3 `);
176165
=}
177166

178167
reaction (receive4) -> respond4 {=
179168
respond4 = "pong";
180-
// console.log(`In index: ${index}, ponging: 4 `);
169+
// console.log(`In index: ${index}, ponging: 4 `);
181170
=}
182171

183172
reaction (receive5) -> respond5 {=
184173
respond5 = "pong";
185-
// console.log(`In index: ${index}, ponging: 5 `);
174+
// console.log(`In index: ${index}, ponging: 5 `);
186175
=}
187176

188177
reaction (start, ack1, ack2, ack3, ack4, ack5) -> nextServe, done {=
189178
remainingServes--;
190-
// console.log(`Got ack in index: ${index}, remaining serves: ${remainingServes} `);
179+
// console.log(`Got ack in index: ${index}, remaining serves: ${remainingServes} `);
191180
if (remainingServes == 0) {
181+
remainingServes = limit;
192182
done = null;
193183
} else {
194184
actions.nextServe.schedule(0, null);
@@ -203,37 +193,43 @@ reactor Sink(numberOfActors:number(5)) {
203193
input done3:null;
204194
input done4:null;
205195
input done5:null;
206-
output stopTimer:null;
196+
output stopTimer:boolean;
207197
state count:number(0);
208198

209199
reaction(done1) -> stopTimer {=
210200
count++;
211201
if (count == numberOfActors - 1) {
212-
stopTimer = null;
202+
count = 0;
203+
stopTimer = true;
213204
}
214205
=}
215206
reaction(done2) -> stopTimer {=
216207
count++;
217208
if (count == numberOfActors - 1) {
218-
stopTimer = null;
209+
count = 0;
210+
stopTimer = true;
219211
}
220212
=}
221213
reaction(done3) -> stopTimer {=
222214
count++;
223215
if (count == numberOfActors - 1) {
224-
stopTimer = null;
216+
count = 0;
217+
stopTimer = true;
225218
}
226219
=}
227220
reaction(done4) -> stopTimer {=
228221
count++;
229222
if (count == numberOfActors - 1) {
230-
stopTimer = null;
223+
count = 0;
224+
stopTimer = true;
231225
}
232226
=}
233227
reaction(done5) -> stopTimer {=
234228
count++;
235229
if (count == numberOfActors - 1) {
236-
stopTimer = null;
230+
count = 0;
231+
stopTimer = true;
237232
}
238233
=}
234+
239235
}

TS/Savina/src/micro/Chameneos.lf

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ target TypeScript {
1010
fast: true
1111
};
1212

13-
main reactor Chameneos(limit:number(25000)) {
13+
import BenchmarkRunner from "../BenchmarkRunner.lf";
14+
15+
main reactor Chameneos(numIterations:number(12), limit:number(25000)) {
1416

1517
// Conversions for updateColor from https://wiki.haskell.org/Shootout/Chameneos
1618
preamble {=
17-
enum Color {RED, YELLOW, BLUE};
19+
enum Color {RED, YELLOW, BLUE}
1820
function updateColor(a : Color, b : Color) : Color {
1921
// console.log("Got a: " + a + ", b: " + b);
2022
if (a == Color.RED && b == Color.RED) return Color.RED;
@@ -29,16 +31,12 @@ main reactor Chameneos(limit:number(25000)) {
2931
return null as never;
3032
}
3133
=}
32-
state startTime:time;
33-
reaction (startup) -> m.start {=
34-
m.start = true;
35-
startTime = util.getCurrentPhysicalTime();
36-
=}
37-
reaction (m.done) {=
38-
let elapsedTime = util.getCurrentPhysicalTime().subtract(startTime as TimeValue);
39-
console.log("Elapsed time: " + elapsedTime);
40-
util.requestStop();
41-
=}
34+
35+
runner = new BenchmarkRunner(numIterations=numIterations);
36+
37+
runner.start -> m.start;
38+
m.done -> runner.finish;
39+
4240
m = new Mall(limit = limit);
4341

4442
l0 = new Lizard(initialColor = {= Color.RED =});
@@ -104,6 +102,21 @@ main reactor Chameneos(limit:number(25000)) {
104102
}
105103

106104
reactor Mall(limit:number(25000)) {
105+
106+
preamble {=
107+
function permuteLizards(freeLizards: Array<number>): Array<number> {
108+
const permutedLizards = new Array<number>();
109+
110+
while (freeLizards.length > 0) {
111+
const index = Math.floor(Math.random()*freeLizards.length);
112+
const nextLizard = freeLizards[index];
113+
freeLizards.splice(index, 1);
114+
permutedLizards.push(nextLizard);
115+
}
116+
return permutedLizards;
117+
}
118+
=}
119+
107120
input start:boolean;
108121
input ready0:boolean;
109122
input ready1:boolean;
@@ -123,19 +136,8 @@ reactor Mall(limit:number(25000)) {
123136
// Then repeat for every other available pair of lizards.
124137
reaction (ready0, ready1, ready2, ready3, ready4) -> l0instruction, l1instruction, l2instruction, l3instruction, l4instruction, done {=
125138

126-
function permuteLizards(freeLizards: Array<number>): Array<number> {
127-
let permutedLizards = new Array<number>();
128-
129-
while (freeLizards.length > 0) {
130-
let index = Math.floor(Math.random()*freeLizards.length);
131-
let nextLizard = freeLizards[index];
132-
freeLizards.splice(index, 1);
133-
permutedLizards.push(nextLizard);
134-
}
135-
return permutedLizards;
136-
}
137-
138139
if (count == limit - 1) {
140+
count = 0;
139141
done = true;
140142
} else {
141143
// Randomly permute the ready lizards, then assign pairs as friends
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
target TypeScript{
22
fast: true
33
};
4+
5+
import BenchmarkRunner from "../BenchmarkRunner.lf";
6+
47
reactor Counter(limit:number(25000)) {
58
input receive:number;
69
output done:boolean;
710
state count:number(0);
811
reaction (receive) -> done {=
912
count++;
1013
if (count == limit -1) {
14+
count = 0;
1115
done = true;
1216
}
1317
=}
@@ -21,22 +25,15 @@ reactor Sender {
2125
send = 1;
2226
=}
2327
}
24-
main reactor CountingActor(limit:number(25000)) {
25-
26-
state startTime:time;
28+
main reactor CountingActor(numIterations:number(12), limit:number(25000)) {
29+
30+
runner = new BenchmarkRunner(numIterations = numIterations);
2731

2832
s = new Sender();
2933
c = new Counter(limit = limit);
34+
35+
runner.start -> s.start;
36+
c.done -> runner.finish;
3037

3138
s.send -> c.receive;
32-
33-
reaction (startup) -> s.start {=
34-
s.start = true;
35-
startTime = util.getCurrentPhysicalTime();
36-
=}
37-
reaction (c.done) {=
38-
let elapsedTime = util.getCurrentPhysicalTime().subtract(startTime as TimeValue);
39-
console.log("Elapsed time: " + elapsedTime);
40-
util.requestStop();
41-
=}
4239
}

TS/Savina/src/micro/ThreadRing.lf

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
target TypeScript {
33
fast: true
44
};
5+
6+
import BenchmarkRunner from "../BenchmarkRunner.lf";
7+
58
// To prevent a cycle, one node has to schedule an action upon receiving an input
69
reactor StartNode(limit:number(25000)) {
710
input receive:number;
@@ -44,13 +47,13 @@ reactor Node {
4447
=}
4548
}
4649

47-
main reactor ThreadRing(limit:number(25000)) {
48-
state startTime:time;
50+
main reactor ThreadRing(numIterations:number(12), limit:number(25000)) {
4951
logical action end;
50-
reaction (startup) -> n1.start {=
51-
startTime = util.getCurrentPhysicalTime();
52-
n1.start = true;
53-
=}
52+
53+
runner = new BenchmarkRunner(numIterations=numIterations);
54+
55+
runner.start -> n1.start;
56+
5457
reaction (n1.done) -> end {=
5558
actions.end.schedule(0, null);
5659
=}
@@ -66,13 +69,10 @@ main reactor ThreadRing(limit:number(25000)) {
6669
reaction (n5.done) -> end {=
6770
actions.end.schedule(0, null);
6871
=}
69-
reaction (end) {=
70-
if (startTime) {
71-
let elapsedTime = util.getCurrentPhysicalTime().subtract(startTime);
72-
console.log("Elapsed time: " + elapsedTime);
73-
util.requestStop();
74-
}
72+
reaction (end) -> runner.finish {=
73+
runner.finish = true;
7574
=}
75+
7676
n1 = new StartNode(limit = limit);
7777
n2 = new Node();
7878
n3 = new Node();

runner/conf/benchmark/savina_micro_big.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ targets:
4848
run_args:
4949
messages: ["--main-num-pings-per-reactor", "<value>"]
5050
actors: ["--main-num-reactors", "<value>"]
51+
lf-ts:
52+
copy_sources:
53+
- "${bench_path}/TS/Savina/src/BenchmarkRunner.lf"
54+
- "${bench_path}/TS/Savina/src/micro"
55+
lf_file: "micro/Big.lf"
56+
script: "src-gen/micro/Big/dist/Big.js"
57+
gen_args:
58+
messages: ["-D", "numPingsPerReactor=<value>"]
59+
actors: ["-D", "numReactors=<value>"]

runner/conf/benchmark/savina_micro_chameneos.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,11 @@ targets:
4545
run_args:
4646
meetings: ["--main-num-meetings", "<value>"]
4747
chameneos: ["--main-num-chameneos", "<value>"]
48+
lf-ts:
49+
copy_sources:
50+
- "${bench_path}/TS/Savina/src/BenchmarkRunner.lf"
51+
- "${bench_path}/TS/Savina/src/micro"
52+
lf_file: "micro/Chameneos.lf"
53+
script: "src-gen/micro/Chameneos/dist/Chameneos.js"
54+
gen_args:
55+
meetings: ["-D", "limit=<value>"]

runner/conf/benchmark/savina_micro_count.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,11 @@ targets:
3939
binary: "counting"
4040
run_args:
4141
messages: ["--main-count-to", "<value>"]
42+
lf-ts:
43+
copy_sources:
44+
- "${bench_path}/TS/Savina/src/BenchmarkRunner.lf"
45+
- "${bench_path}/TS/Savina/src/micro"
46+
lf_file: "micro/CountingActor.lf"
47+
script: "src-gen/micro/CountingActor/dist/CountingActor.js"
48+
gen_args:
49+
messages: ["-D", "limit=<value>"]

0 commit comments

Comments
 (0)