extend ByteString benchmarks (#2154)

* extend ByteString benchmarks

* Update ByteString_indexOf_Benchmark.scala
This commit is contained in:
PJ Fanning 2025-09-06 09:18:14 +01:00 committed by GitHub
parent 72808dc035
commit 6e436584ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 58 additions and 1 deletions

View file

@ -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)
}

View file

@ -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)
}