From a77d64d00f8cc9975479bc0a417021c6e949ff05 Mon Sep 17 00:00:00 2001 From: martinvuyk Date: Fri, 20 Dec 2024 16:59:25 -0300 Subject: [PATCH] even more perf, update benchmark numbers Signed-off-by: martinvuyk --- stdlib/benchmarks/collections/bench_string.mojo | 7 ++++--- stdlib/src/utils/string_slice.mojo | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/stdlib/benchmarks/collections/bench_string.mojo b/stdlib/benchmarks/collections/bench_string.mojo index fc5dfc718e..b37f9ff291 100644 --- a/stdlib/benchmarks/collections/bench_string.mojo +++ b/stdlib/benchmarks/collections/bench_string.mojo @@ -10,7 +10,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # ===----------------------------------------------------------------------=== # -# RUN: %mojo-no-debug %s -t +# RUN: %mojo-no-debug %s # NOTE: to test changes on the current branch using run-benchmarks.sh, remove # the -t flag. Remember to replace it again before pushing any code. @@ -23,6 +23,7 @@ from random import random_si64, seed from benchmark import Bench, BenchConfig, Bencher, BenchId, Unit, keep, run from utils._utf8_validation import _is_valid_utf8 +from utils import StringSlice # ===-----------------------------------------------------------------------===# @@ -111,7 +112,7 @@ fn bench_string_split[ @always_inline @parameter fn call_fn() raises: - var res: List[String] + var res: List[StringSlice[__origin_of(items)]] @parameter if sequence: @@ -237,7 +238,7 @@ def main(): ) alias old_chars = ("a", "ó", "ل", "и", "一") alias new_chars = ("A", "Ó", "ل", "И", "一") - alias lengths = (10, 30, 50, 100, 1000, 10_000, 100_000, 1_000_000) + alias lengths = (1_000_000,) """At an average 5 letters per word and 300 words per page (in the English language): diff --git a/stdlib/src/utils/string_slice.mojo b/stdlib/src/utils/string_slice.mojo index 43197deb7b..3b3e399085 100644 --- a/stdlib/src/utils/string_slice.mojo +++ b/stdlib/src/utils/string_slice.mojo @@ -1358,11 +1358,11 @@ fn _split[ # FIXME(#3526): use str_span and sep_span rhs = src_str.find(sep, lhs) # if not found go to the end - rhs += int(rhs == -1) * (str_byte_len + 1) + rhs += -int(rhs == -1) & (str_byte_len + 1) @parameter if has_maxsplit: - rhs += int(items == maxsplit) * (str_byte_len - rhs) + rhs += -int(items == maxsplit) & (str_byte_len - rhs) items += 1 output.append(S(ptr=ptr + lhs, length=rhs - lhs)) @@ -1415,7 +1415,7 @@ fn _split[ @parameter if has_maxsplit: - rhs += int(items == maxsplit) * (str_byte_len - rhs) + rhs += -int(items == maxsplit) & (str_byte_len - rhs) items += 1 output.append(S(ptr=ptr + lhs, length=rhs - lhs))