-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix scanner for input larger than internal buffer
- Loading branch information
1 parent
502e020
commit 7dfe559
Showing
4 changed files
with
40 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,34 @@ | ||
import benchmark | ||
import gojo.bufio | ||
import gojo.bytes | ||
import gojo.strings | ||
import testing | ||
|
||
|
||
fn benchmark_scan_runes() -> None: | ||
var input = String("Hello, World!").as_bytes() | ||
var buf = bytes.Buffer(buf=input^) | ||
var scanner = bufio.Scanner[split = bufio.scan_runes](buf^) | ||
alias FIRE = "🔥" | ||
|
||
|
||
fn benchmark_scan_runes[batches: Int]() -> None: | ||
var builder = strings.StringBuilder(capacity=batches) | ||
for _ in range(batches): | ||
_ = builder.write_string(FIRE) | ||
|
||
var buf = bytes.Buffer(buf=str(builder).as_bytes()) | ||
var scanner = bufio.Scanner[split = bufio.scan_runes, capacity=batches](buf^) | ||
while scanner.scan(): | ||
print(scanner.current_token()) | ||
_ = scanner.current_token() | ||
|
||
|
||
fn main(): | ||
print("Running benchmark_scan_runes") | ||
var report = benchmark.run[benchmark_scan_runes](max_iters=20) | ||
# There's a time penalty for building the input text, for now. | ||
print("Running benchmark_scan_runes - 100") | ||
var report = benchmark.run[benchmark_scan_runes[100]](max_iters=20) | ||
report.print(benchmark.Unit.ms) | ||
|
||
print("Running benchmark_scan_runes - 1000") | ||
report = benchmark.run[benchmark_scan_runes[1000]](max_iters=20) | ||
report.print(benchmark.Unit.ms) | ||
|
||
print("Running benchmark_scan_runes - 10000") | ||
report = benchmark.run[benchmark_scan_runes[10000]](max_iters=20) | ||
report.print(benchmark.Unit.ms) |
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