Skip to content

Commit

Permalink
заготовка для второго семинара
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim Valyanskiy committed Jan 30, 2020
1 parent 71a0c2d commit eeee462
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ _site
.jekyll-metadata
vendor
.bundle
target
.idea
1 change: 1 addition & 0 deletions code/seminar1/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version = 1.3.7
7 changes: 7 additions & 0 deletions code/seminar2/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name := "seminar2"

version := "0.1"

scalaVersion := "2.13.1"

enablePlugins(JmhPlugin)
1 change: 1 addition & 0 deletions code/seminar2/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version = 1.3.7
1 change: 1 addition & 0 deletions code/seminar2/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.7")
24 changes: 24 additions & 0 deletions code/seminar2/src/main/scala/benchmarks/CollectionBenchmarks.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package benchmarks

import java.util.concurrent.TimeUnit

import org.openjdk.jmh.annotations._

import scala.util.Random

// sbt
// jmh:run -f 1 -i 1
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@BenchmarkMode(Array(Mode.Throughput))
class CollectionBenchmarks {
@Benchmark
def listAppend(scope: BenchmarkState) = scope.randomList :+ 1

@Benchmark
def listPrepend(scope: BenchmarkState) = 1 +: scope.randomList
}

@State(Scope.Benchmark)
class BenchmarkState {
val randomList: List[Int] = List.fill(10000)(Random.nextInt())
}

0 comments on commit eeee462

Please sign in to comment.