This is an automated email from the ASF dual-hosted git repository.
fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/main by this push:
new 6e436584ac extend ByteString benchmarks (#2154)
6e436584ac is described below
commit 6e436584ac9382989f7714554df95f3f49d40174
Author: PJ Fanning <[email protected]>
AuthorDate: Sat Sep 6 09:18:14 2025 +0100
extend ByteString benchmarks (#2154)
* extend ByteString benchmarks
* Update ByteString_indexOf_Benchmark.scala
---
.../pekko/util/ByteString_indexOf_Benchmark.scala | 10 ++++-
.../util/ByteString_lastIndexOf_Benchmark.scala | 49 ++++++++++++++++++++++
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git
a/bench-jmh/src/main/scala/org/apache/pekko/util/ByteString_indexOf_Benchmark.scala
b/bench-jmh/src/main/scala/org/apache/pekko/util/ByteString_indexOf_Benchmark.scala
index 4eab26438e..1b6c6d2a81 100644
---
a/bench-jmh/src/main/scala/org/apache/pekko/util/ByteString_indexOf_Benchmark.scala
+++
b/bench-jmh/src/main/scala/org/apache/pekko/util/ByteString_indexOf_Benchmark.scala
@@ -24,6 +24,8 @@ class ByteString_indexOf_Benchmark {
val bss = start ++ start ++ start ++ start ++ start ++ ByteString("xyz")
val bs = bss.compact // compacted
+ val oByte = 'o'.toByte
+ val zByte = 'z'.toByte
/*
original
@@ -46,10 +48,16 @@ class ByteString_indexOf_Benchmark {
@Benchmark
def bss_indexOf_from_far_index_case: Int = bss.indexOf('z', 109)
+ @Benchmark
+ def bss_indexOf_from_far_index_case_byte: Int = bss.indexOf(zByte, 109)
+
@Benchmark
def bss_indexOf_from_best_case: Int = bss.indexOf('a', 0)
@Benchmark
- def bs1_indexOf_from: Int = bs.indexOf('รถ', 5)
+ def bs1_indexOf_from: Int = bs.indexOf('o', 5)
+
+ @Benchmark
+ def bs1_indexOf_from_byte: Int = bs.indexOf(oByte, 5)
}
diff --git
a/bench-jmh/src/main/scala/org/apache/pekko/util/ByteString_lastIndexOf_Benchmark.scala
b/bench-jmh/src/main/scala/org/apache/pekko/util/ByteString_lastIndexOf_Benchmark.scala
new file mode 100644
index 0000000000..b809c0bf5b
--- /dev/null
+++
b/bench-jmh/src/main/scala/org/apache/pekko/util/ByteString_lastIndexOf_Benchmark.scala
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+/*
+ * Copyright (C) 2014-2022 Lightbend Inc. <https://www.lightbend.com>
+ */
+
+package org.apache.pekko.util
+
+import java.util.concurrent.TimeUnit
+
+import org.openjdk.jmh.annotations._
+
+@State(Scope.Benchmark)
+@Measurement(timeUnit = TimeUnit.MILLISECONDS)
+class ByteString_lastIndexOf_Benchmark {
+ val start = ByteString("abcdefg") ++ ByteString("hijklmno") ++
ByteString("pqrstuv")
+ val bss = start ++ start ++ start ++ start ++ start ++ ByteString("xyz")
+
+ val bs = bss.compact // compacted
+ val bsLen = bs.length
+ val aByte = 'a'.toByte
+ val oByte = 'o'.toByte
+
+ @Benchmark
+ def bss_lastIndexOf_worst_case: Int = bss.lastIndexOf('a')
+
+ @Benchmark
+ def bss_lastIndexOf_far_index_case: Int = bss.lastIndexOf('a', 10)
+
+ @Benchmark
+ def bss_lastIndexOf_far_index_case_byte: Int = bss.lastIndexOf(aByte, 10)
+
+ @Benchmark
+ def bss_lastIndexOf_best_case: Int = bss.lastIndexOf('z')
+
+ @Benchmark
+ def bs1_lastIndexOf: Int = bs.lastIndexOf('o', bsLen - 5)
+
+ @Benchmark
+ def bs1_lastIndexOf_byte: Int = bs.lastIndexOf(oByte, bsLen - 5)
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]