@@ -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
106104reactor 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
0 commit comments