Skip to content
Snippets Groups Projects
Commit cb470dd4 authored by Krebs, Matthias's avatar Krebs, Matthias
Browse files

exercise 09 task 3

parents
No related branches found
No related tags found
No related merge requests found
# scala/sbt
target/
.bsp/
*.class
# intellij
*.iml
*.ipr
*.iws
.idea
out/
# Exercise 11
Skeleton for task 3.
## sbt-jmh
This project uses the jmh plugin of sbt. You can run the benchmarks through `sbt Jmh/run`.
ThisBuild / version := "0.9.0"
ThisBuild / scalaVersion := "3.3.1"
lazy val root = (project in file("."))
.settings(
name := "exercise11"
)
enablePlugins(JmhPlugin)
sbt.version = 1.9.8
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.7")
package collections
import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.Blackhole
import java.util.concurrent.TimeUnit
import scala.collection.mutable.ArrayBuffer
import scala.util.Random
class ArrayBufferOps:
???
\ No newline at end of file
package collections
import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.Blackhole
import java.util.concurrent.TimeUnit
import scala.collection.mutable.ListBuffer
import scala.util.Random
class ListBufferOps:
???
\ No newline at end of file
package collections
import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.Blackhole
import java.util.concurrent.TimeUnit
import scala.util.Random
class ListOps:
???
\ No newline at end of file
package objects
import org.openjdk.jmh.annotations.*
import org.openjdk.jmh.infra.Blackhole
import java.util.concurrent.TimeUnit
@BenchmarkMode(Array(Mode.AverageTime))
@OutputTimeUnit(TimeUnit.NANOSECONDS)
@Warmup(iterations = 10, time = 100, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 100, time = 10, timeUnit = TimeUnit.MILLISECONDS)
@Fork(1)
@State(Scope.Thread)
class ObjectCreationTime:
@Benchmark
def noop(): Unit = ()
@Benchmark
def createObject(): Unit =
SomeConcept()
class SomeConcept
\ No newline at end of file
package sort
import org.openjdk.jmh.annotations.*
import java.util.concurrent.TimeUnit
import collection.immutable.ArraySeq
import scala.util.Random
@BenchmarkMode(Array(Mode.AverageTime))
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@Warmup(iterations = 10, time = 200, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 40, time = 100, timeUnit = TimeUnit.MILLISECONDS)
@Fork(1)
@State(Scope.Benchmark)
class ArraySort:
@Param(Array("1000", "10000", "100000"))
var size: Int = _
var array: ArraySeq[Int] = _
@Setup
def fillArray(): Unit = array = ArraySeq.fill(size)(Random.nextInt())
@Benchmark
def sortAscending(): ArraySeq[Int] = array.sorted
@Benchmark
def sortDescending(): ArraySeq[Int] = array.sortWith(_>_)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment