Skip to content

Instantly share code, notes, and snippets.

@fserra-mdsol
Created May 25, 2024 17:03
Show Gist options
  • Save fserra-mdsol/5c3c7e1fe2f3c4c9938db61126d3ab1f to your computer and use it in GitHub Desktop.
Save fserra-mdsol/5c3c7e1fe2f3c4c9938db61126d3ab1f to your computer and use it in GitHub Desktop.
compare asymptotic complexity of pipelined transformations with/without using views
//> using scala "2.13.13"
package bench
import org.openjdk.jmh.annotations._
import Bench._
class asymptoticOptTests {
@Benchmark
def O2n = hundred
.map(foo => Foo(foo.value / 10))
.sortBy(_.value)
.map(_.value.toString)
@Benchmark
def On = hundred
.view.map(foo => Foo(foo.value / 10))
.sortBy(_.value)
.map(_.value.toString)
.toList
}
object Bench {
case class Foo(value: Int)
val hundred: List[Foo] = List.range(1,100).map(Foo(_))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment