Skip to content

Commit 18dae1a

Browse files
phischuserkmmarvinborner
authored
More filesystem benchmarks (#802)
@marvinborner I would like these and the other benchmarks in `input_output` integrated into effekt plots. --------- Co-authored-by: Serkan Muhcu <[email protected]> Co-authored-by: Marvin Borner <[email protected]>
1 parent d5e9f08 commit 18dae1a

17 files changed

+361
-8
lines changed

effekt/jvm/src/test/scala/effekt/ChezSchemeTests.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ abstract class ChezSchemeTests extends EffektTests {
3232
examplesDir / "benchmarks" / "input_output" / "word_count_utf8.effekt",
3333
examplesDir / "benchmarks" / "input_output" / "dyck_one.effekt",
3434
examplesDir / "benchmarks" / "input_output" / "number_matrix.effekt",
35+
examplesDir / "benchmarks" / "input_output" / "large_file.effekt",
36+
examplesDir / "benchmarks" / "input_output" / "small_files.effekt",
37+
examplesDir / "benchmarks" / "input_output" / "interleave_promises.effekt",
38+
examplesDir / "benchmarks" / "input_output" / "financial_format.effekt",
3539

3640
// unsafe continuations are not yet supported in our Chez backend
3741
examplesDir / "pos" / "unsafe_cont.effekt",

examples/benchmarks/config_js.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ effect_handlers_bench/product_early 32768
2222
effect_handlers_bench/resume_nontail 1366
2323
effect_handlers_bench/tree_explore 14
2424
effect_handlers_bench/triples 256
25+
input_output/large_file 6000
26+
input_output/small_files 2000
27+
input_output/interleave_promises 100
28+
input_output/word_count_ascii 8000
29+
input_output/word_count_utf8 15000
30+
input_output/dyck_one 800
31+
input_output/number_matrix 700
32+
input_output/financial_format 15000

examples/benchmarks/config_llvm.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ effect_handlers_bench/product_early 262144
2222
effect_handlers_bench/resume_nontail 65536
2323
effect_handlers_bench/tree_explore 17
2424
effect_handlers_bench/triples 512
25+
input_output/large_file 60000
26+
input_output/small_files 20000
27+
input_output/interleave_promises 300
28+
input_output/word_count_ascii 20000
29+
input_output/word_count_utf8 80000
30+
input_output/dyck_one 3000
31+
input_output/number_matrix 2000
32+
input_output/financial_format 200000
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
206
1+
20

examples/benchmarks/input_output/dyck_one.effekt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ import stream
66
import scanner
77

88
// dyck_one.txt
9-
// ((((()())(()())(()()))((()())(()())(()()))((()())(()())(()()))((()())(()())(()())))...
9+
// (()()()()()(()()()()(()()()(()()(())))))
1010

1111
def emitTree(n: Int): Unit / emit[Byte] =
1212
if (n <= 0) {
1313
()
1414
} else {
1515
do emit(40.toByte)
16-
repeat(n) { emitTree(n - 1) }
16+
repeat(n) {
17+
do emit(40.toByte)
18+
do emit(41.toByte)
19+
}
20+
emitTree(n - 1)
1721
do emit(41.toByte)
1822
}
1923

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import examples/benchmarks/runner
2+
3+
import bytearray
4+
import char
5+
import io/error
6+
import io/filesystem
7+
import stream
8+
9+
10+
def emitEntry(tag: Int) { value: () => Unit / emit[Byte] }: Unit / emit[Byte] = {
11+
tag.show.fromString.each()
12+
do emit(61.toByte)
13+
value()
14+
do emit(01.toByte)
15+
}
16+
17+
def emitOrder(): Unit / emit[Byte] = {
18+
emitEntry(8) { "FIX.4.4".fromString.each() }
19+
emitEntry(9) { "176".fromString.each() }
20+
emitEntry(35) { "D".fromString.each() }
21+
emitEntry(49) { "Sender".fromString.each() }
22+
emitEntry(56) { "Target".fromString.each() }
23+
emitEntry(34) { "123".fromString.each() }
24+
emitEntry(52) { "20250124-16:00:00.000".fromString.each() }
25+
26+
emitEntry(11) { "12345".fromString.each() }
27+
emitEntry(55) { "AAPL".fromString.each() }
28+
emitEntry(54) { "1".fromString.each() }
29+
emitEntry(38) { "100".fromString.each() }
30+
emitEntry(40) { "2".fromString.each() }
31+
emitEntry(44) { "150.00".fromString.each() }
32+
33+
emitEntry(10) { "123".fromString.each() }
34+
}
35+
36+
def readTag(): Int / read[Byte] = {
37+
var tag = 0
38+
exhaustively {
39+
val byte = do read[Byte]().toInt
40+
if (byte >= 48 && byte <= 57) {
41+
tag = tag * 10 + (byte - 48)
42+
} else {
43+
do stop()
44+
}
45+
}
46+
return tag
47+
}
48+
49+
def readEntry { entry: Int => Unit / read[Byte] }: Unit / read[Byte] = {
50+
val tag = readTag()
51+
try {
52+
entry(tag)
53+
} with read[Byte] {
54+
resume {
55+
val byte = do read[Byte]()
56+
if (byte.toInt == 1) {
57+
do stop()
58+
} else {
59+
byte
60+
}
61+
}
62+
}
63+
}
64+
65+
def readOrder(): Unit / read[Byte] = {
66+
def assertTag(tag: Int) = {
67+
readEntry { got =>
68+
if (got == tag) {
69+
exhaustively { do read[Byte](); () }
70+
} else {
71+
panic("wrong tag")
72+
}
73+
}
74+
}
75+
assertTag(8)
76+
assertTag(9)
77+
assertTag(35)
78+
assertTag(49)
79+
assertTag(56)
80+
assertTag(34)
81+
assertTag(52)
82+
83+
assertTag(11)
84+
assertTag(55)
85+
assertTag(54)
86+
assertTag(38)
87+
assertTag(40)
88+
assertTag(44)
89+
90+
assertTag(10)
91+
}
92+
93+
94+
def run(n: Int) = {
95+
with on[IOError].panic;
96+
97+
val filename = "/tmp/financial_information_exchange.txt"
98+
val size = 4096
99+
100+
writeFile(filename) {
101+
repeat(n) {
102+
emitOrder()
103+
}
104+
}
105+
106+
readFile(filename) {
107+
repeat(n) {
108+
readOrder()
109+
}
110+
}
111+
112+
return 0
113+
114+
}
115+
116+
def main() = benchmark(5){run}
117+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import examples/benchmarks/runner
2+
3+
import bytearray
4+
import list
5+
import io
6+
import io/error
7+
import io/filesystem
8+
9+
10+
def run(n: Int) = {
11+
with on[IOError].panic;
12+
13+
val foldername = "/tmp/interleave_promises/"
14+
val size = 4096
15+
16+
on[IOError].result { mkdir(foldername) } match {
17+
case Error(EEXIST(), msg) => ()
18+
case Error(e, m) => do raise(e, m)
19+
case Success(()) => ()
20+
}
21+
22+
val promises = list::build(n) { i =>
23+
promise(box {
24+
with on[IOError].result
25+
val filename = foldername ++ i.show ++ ".txt"
26+
val file = openForWriting(filename)
27+
val buffer = bytearray(size, 35.toByte)
28+
repeat(n) {
29+
val m = write(file, buffer, 0, size, -1)
30+
if (m < buffer.size) {
31+
panic("failed write")
32+
}
33+
}
34+
close(file)
35+
})
36+
}
37+
38+
promises.foreachIndex { (i, p) =>
39+
p.await().value()
40+
val filename = foldername ++ i.show ++ ".txt"
41+
val file = openForReading(filename)
42+
val buffer = bytearray::allocate(size)
43+
repeat(n) {
44+
val m = read(file, buffer, 0, size, -1)
45+
if (m < buffer.size) {
46+
panic("failed read")
47+
}
48+
}
49+
close(file)
50+
}
51+
52+
return 0
53+
}
54+
55+
def main() = benchmark(5){run}
56+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

0 commit comments

Comments
 (0)