-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Effects for push and pulls streams and handlers for them. --------- Co-authored-by: Jonathan Brachthäuser <[email protected]>
- Loading branch information
Showing
15 changed files
with
641 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
6170 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import examples/benchmarks/runner | ||
|
||
import io/error | ||
import io/filesystem | ||
import stream | ||
|
||
record Output(chars: Int, words: Int, lines: Int) | ||
|
||
def formatWith(output: Output, filename: String): String = | ||
output.lines.show ++ " " ++ output.words.show ++ " " ++ output.chars.show ++ " " ++ filename | ||
|
||
def isSpace(b: Byte) = b.toInt match { | ||
case 32 => true // ' ' | ||
case 9 => true // '\t' | ||
case 10 => true // '\n' | ||
case 11 => true // '\v' | ||
case 12 => true // '\f' | ||
case 13 => true // '\r' | ||
case _ => false | ||
} | ||
|
||
def isNewline(b: Byte) = b.toInt == 10 // \n | ||
|
||
def countWords(): Output / read[Byte] = { | ||
|
||
var chars = 0 | ||
var words = 0 | ||
var lines = 0 | ||
var wasSpace = true | ||
|
||
exhaustively { do read[Byte]() } { c => | ||
|
||
chars = chars + 1 | ||
|
||
val currentIsSpace = isSpace(c) | ||
|
||
if (wasSpace && not(currentIsSpace)) { | ||
words = words + 1 | ||
} | ||
wasSpace = currentIsSpace | ||
|
||
if (isNewline(c)) { | ||
lines = lines + 1 | ||
} | ||
} | ||
|
||
Output(chars, words, lines) | ||
} | ||
|
||
def run(n: Int) = { | ||
with on[IOError].panic; | ||
|
||
val filename = "/tmp/word_count_ascii.txt" | ||
|
||
val _ = { | ||
with writeFile(filename) | ||
with repeat(n) | ||
for[Int] { range(32, 127) } { c => | ||
repeat(10) { | ||
do emit(c.toByte) | ||
} | ||
do emit(10.toByte) | ||
} | ||
} | ||
|
||
val output = { | ||
with readFile(filename) | ||
countWords() | ||
} | ||
|
||
return output.chars + output.words + output.lines | ||
} | ||
|
||
def main() = benchmark(5){run} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
650 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import examples/benchmarks/runner | ||
|
||
import io/error | ||
import io/filesystem | ||
import char | ||
import stream | ||
|
||
record Output(chars: Int, words: Int, lines: Int) | ||
|
||
def formatWith(output: Output, filename: String): String = | ||
output.lines.show ++ " " ++ output.words.show ++ " " ++ output.chars.show ++ " " ++ filename | ||
|
||
def countWords(): Output / read[Char] = { | ||
|
||
var chars = 0 | ||
var words = 0 | ||
var lines = 0 | ||
var wasSpace = true | ||
|
||
exhaustively[Char] { do read() } { c => | ||
|
||
chars = chars + 1 | ||
|
||
val currentIsSpace = isWhitespace(c) | ||
|
||
if (wasSpace && not(currentIsSpace)) { | ||
words = words + 1 | ||
} | ||
wasSpace = currentIsSpace | ||
|
||
if (c == '\n') { | ||
lines = lines + 1 | ||
} | ||
} | ||
|
||
Output(chars, words, lines) | ||
} | ||
|
||
def run(n: Int) = { | ||
with on[IOError].panic; | ||
|
||
val filename = "/tmp/word_count_utf8.txt" | ||
|
||
val _ = { | ||
with writeFile(filename) | ||
with encodeUTF8 | ||
with repeat(n) | ||
for[Int] { range(128512, 128522) } { c => | ||
repeat(10) { | ||
do emit(c.toChar) | ||
} | ||
do emit(10.toChar) | ||
} | ||
} | ||
|
||
val output = { | ||
with readFile(filename) | ||
with decodeUTF8 | ||
countWords() | ||
} | ||
|
||
return output.chars + output.words + output.lines | ||
} | ||
|
||
def main() = benchmark(5){run} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,5 +11,5 @@ def main() = { | |
|
||
b.unsafeSet(1, 102.toByte) | ||
|
||
println(b.toUTF8) // hfllo | ||
println(b.toString) // hfllo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.