Created
May 25, 2024 17:03
-
-
Save fserra-mdsol/5c3c7e1fe2f3c4c9938db61126d3ab1f to your computer and use it in GitHub Desktop.
compare asymptotic complexity of pipelined transformations with/without using views
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//> 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