Skip to content

Instantly share code, notes, and snippets.

@fserra-mdsol
Created May 25, 2024 18:41
Show Gist options
  • Save fserra-mdsol/d36320855b65d1b4ff658683526d9c1f to your computer and use it in GitHub Desktop.
Save fserra-mdsol/d36320855b65d1b4ff658683526d9c1f to your computer and use it in GitHub Desktop.
//> using scala "2.13.13"
package bench
import org.openjdk.jmh.annotations._
import Bench2._
@State(Scope.Benchmark)
class asymptoticOptTests2 {
@Benchmark
def On = initial.foreach(foo =>
initial.find(_.value == foo.value).map(_.ss).getOrElse(List.empty)
)
@Benchmark
def O1 =
initial.foreach(foo => map.getOrElse(foo.value, List.empty))
}
object Bench2 {
case class Foo(value: Int, ss: List[String])
val initial = List.range(1,100).map(i => Foo(i, List.range(1,i).map(_.toString)))
val map = initial.groupMapReduce(_.value)(_.ss)(_ ::: _)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment