-
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.
add more benchmarks, but scanner needs to be fixed now
- Loading branch information
1 parent
fff4eea
commit de8b662
Showing
5 changed files
with
130 additions
and
151 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import benchmark | ||
import gojo.bufio | ||
import gojo.bytes | ||
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^) | ||
|
||
while scanner.scan(): | ||
print(scanner.current_token()) | ||
|
||
|
||
fn main(): | ||
print("Running benchmark_scan_runes") | ||
var report = benchmark.run[benchmark_scan_runes](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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# fn test_std_writer_speed() raises: | ||
# """STDWriter is roughly 6-7x faster currently.""" | ||
# var print_start_time = now() | ||
# for i in range(1, 10000): | ||
# print(i) | ||
# var print_execution_time = now() - print_start_time | ||
|
||
# # Create stdout writer | ||
# var writer = STDWriter(1) | ||
# var writer_start_time = now() | ||
# for i in range(1, 10000): | ||
# _ = writer.write_string(str(i)) | ||
# var writer_execution_time = now() - writer_start_time | ||
|
||
# print("\n\nprint execution time (s): " + str((print_execution_time) / 1e9)) | ||
# print("writer execution time (s): " + str((writer_execution_time) / 1e9)) | ||
# print("Writer is ", str(print_execution_time // writer_execution_time) + "x faster") |
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,92 @@ | ||
import benchmark | ||
from gojo.strings import StringBuilder | ||
from gojo.bytes.buffer import Buffer | ||
|
||
|
||
fn benchmark_concat[batches: Int = 10000](): | ||
var vec = List[String]() | ||
for _ in range(batches): | ||
vec.append( | ||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod" | ||
" tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim" | ||
" veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea" | ||
" commodo consequat. Duis aute irure dolor in reprehenderit in voluptate" | ||
" velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint" | ||
" occaecat cupidatat non proident, sunt in culpa qui officia deserunt" | ||
" mollit anim id est laborum." | ||
) | ||
|
||
var concat_output: String = "" | ||
for i in range(len(vec)): | ||
concat_output += vec[i] | ||
_ = concat_output | ||
|
||
|
||
fn benchmark_string_builder[batches: Int = 10000](): | ||
var new_builder = StringBuilder() | ||
for _ in range(batches): | ||
_ = new_builder.write_string( | ||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod" | ||
" tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim" | ||
" veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea" | ||
" commodo consequat. Duis aute irure dolor in reprehenderit in voluptate" | ||
" velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint" | ||
" occaecat cupidatat non proident, sunt in culpa qui officia deserunt" | ||
" mollit anim id est laborum." | ||
) | ||
_ = str(new_builder) | ||
|
||
|
||
fn benchmark_bytes_buffer[batches: Int = 10000](): | ||
var buffer = Buffer() | ||
for _ in range(batches): | ||
_ = buffer.write_string( | ||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod" | ||
" tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim" | ||
" veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea" | ||
" commodo consequat. Duis aute irure dolor in reprehenderit in voluptate" | ||
" velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint" | ||
" occaecat cupidatat non proident, sunt in culpa qui officia deserunt" | ||
" mollit anim id est laborum." | ||
) | ||
_ = str(buffer) | ||
|
||
|
||
fn main(): | ||
# There's a performance penalty for benchmark concat bc it also includes | ||
# the building of the list of strings it concatenates. Trying to build it at comptime takes a loooong time. | ||
print("Running benchmark_concat - 100 batches") | ||
var report = benchmark.run[benchmark_concat[100]](max_iters=20) | ||
report.print(benchmark.Unit.ms) | ||
|
||
print("Running benchmark_string_builder - 100 batches") | ||
report = benchmark.run[benchmark_string_builder[100]](max_iters=20) | ||
report.print(benchmark.Unit.ms) | ||
|
||
print("Running benchmark_bytes_buffer - 100 batches") | ||
report = benchmark.run[benchmark_bytes_buffer[100]](max_iters=20) | ||
report.print(benchmark.Unit.ms) | ||
|
||
print("Running benchmark_concat - 1000 batches") | ||
report = benchmark.run[benchmark_concat[1000]](max_iters=20) | ||
report.print(benchmark.Unit.ms) | ||
|
||
print("Running benchmark_string_builder - 1000 batches") | ||
report = benchmark.run[benchmark_string_builder[1000]](max_iters=20) | ||
report.print(benchmark.Unit.ms) | ||
|
||
print("Running benchmark_bytes_buffer - 1000 batches") | ||
report = benchmark.run[benchmark_bytes_buffer[1000]](max_iters=20) | ||
report.print(benchmark.Unit.ms) | ||
|
||
print("Running benchmark_concat - 10000 batches") | ||
report = benchmark.run[benchmark_concat[10000]](max_iters=2) | ||
report.print(benchmark.Unit.ms) | ||
|
||
print("Running benchmark_string_builder - 10000 batches") | ||
report = benchmark.run[benchmark_string_builder[10000]](max_iters=20) | ||
report.print(benchmark.Unit.ms) | ||
|
||
print("Running benchmark_bytes_buffer - 10000 batches") | ||
report = benchmark.run[benchmark_bytes_buffer[10000]](max_iters=20) | ||
report.print(benchmark.Unit.ms) |
This file was deleted.
Oops, something went wrong.
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