From 5403b1eebf1418f4503c834820118410fad7acec Mon Sep 17 00:00:00 2001 From: Mikhail Tavarez Date: Wed, 11 Sep 2024 21:41:28 -0500 Subject: [PATCH] up max version --- benchmarks/scanner.mojo | 20 +++++++--------- benchmarks/string_builder.mojo | 44 +++++++++------------------------- 2 files changed, 19 insertions(+), 45 deletions(-) diff --git a/benchmarks/scanner.mojo b/benchmarks/scanner.mojo index 71e23f1..a97e7db 100644 --- a/benchmarks/scanner.mojo +++ b/benchmarks/scanner.mojo @@ -12,36 +12,33 @@ alias SPACE = " " fn benchmark_scan_runes[batches: Int]() -> None: - var builder = strings.StringBuilder(capacity=batches) + var builder = strings.StringBuilder(capacity=batches * 4) 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^) + var scanner = bufio.Scanner[bufio.scan_runes](bytes.Buffer(buf=str(builder).as_bytes()), capacity=batches) while scanner.scan(): _ = scanner.current_token() fn benchmark_scan_words[batches: Int]() -> None: - var builder = strings.StringBuilder(capacity=batches) + var builder = strings.StringBuilder(capacity=batches * 5) for _ in range(batches): _ = builder.write_string(FIRE) _ = builder.write_string(SPACE) - var buf = bytes.Buffer(str(builder)) - var scanner = bufio.Scanner[split = bufio.scan_words, capacity=batches](buf^) + var scanner = bufio.Scanner[bufio.scan_words](bytes.Buffer(str(builder)), capacity=batches) while scanner.scan(): _ = scanner.current_token() fn benchmark_scan_lines[batches: Int]() -> None: - var builder = strings.StringBuilder(capacity=batches) + var builder = strings.StringBuilder(capacity=batches * 5) for _ in range(batches): _ = builder.write_string(FIRE) _ = builder.write_string(NEWLINE) - var buf = bytes.Buffer(str(builder)) - var scanner = bufio.Scanner[capacity=batches](buf^) + var scanner = bufio.Scanner(bytes.Buffer(str(builder)), capacity=batches) while scanner.scan(): _ = scanner.current_token() @@ -51,14 +48,13 @@ fn benchmark_scan_bytes[batches: Int]() -> None: for _ in range(batches): _ = builder.write_string(SPACE) - var buf = bytes.Buffer(str(builder)) - var scanner = bufio.Scanner[split = bufio.scan_bytes, capacity=batches](buf^) + var scanner = bufio.Scanner[bufio.scan_bytes](bytes.Buffer(str(builder)), capacity=batches) while scanner.scan(): _ = scanner.current_token() fn benchmark_newline_split[batches: Int]() -> None: - var builder = strings.StringBuilder(capacity=batches) + var builder = strings.StringBuilder(capacity=batches * 5) for _ in range(batches): _ = builder.write_string(FIRE) _ = builder.write_string(NEWLINE) diff --git a/benchmarks/string_builder.mojo b/benchmarks/string_builder.mojo index 5e48594..423db1f 100644 --- a/benchmarks/string_builder.mojo +++ b/benchmarks/string_builder.mojo @@ -2,19 +2,13 @@ import benchmark from gojo.strings import StringBuilder from gojo.bytes.buffer import Buffer +alias SAMPLE_TEXT = """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.""" -fn benchmark_concat[batches: Int = 10000](): - var vec = List[String]() + +fn benchmark_concat[batches: Int](): + var vec = List[String](capacity=batches * len(SAMPLE_TEXT)) 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." - ) + vec.append(SAMPLE_TEXT) var concat_output: String = "" for i in range(len(vec)): @@ -22,33 +16,17 @@ fn benchmark_concat[batches: Int = 10000](): _ = concat_output -fn benchmark_string_builder[batches: Int = 10000](): - var new_builder = StringBuilder() +fn benchmark_string_builder[batches: Int](): + var new_builder = StringBuilder(capacity=batches * len(SAMPLE_TEXT)) 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." - ) + _ = new_builder.write_string(SAMPLE_TEXT) _ = str(new_builder) -fn benchmark_bytes_buffer[batches: Int = 10000](): - var buffer = Buffer() +fn benchmark_bytes_buffer[batches: Int](): + var buffer = Buffer(capacity=batches * len(SAMPLE_TEXT)) 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." - ) + _ = buffer.write_string(SAMPLE_TEXT) _ = str(buffer)