未验证 提交 56f91116 编写于 作者: D Dejan Mijić 提交者: GitHub

Setup benchmarks (#71)

上级 ca04746e
......@@ -88,7 +88,7 @@ lint: &lint
command: ./sbt ++${SCALA_VERSION}! check
- <<: *save_cache
test: &test
testJVM: &testJVM
steps:
- checkout
- <<: *load_cache
......@@ -99,7 +99,21 @@ test: &test
background: true
- run:
name: Run tests
command: ./sbt ++${SCALA_VERSION}! test
command: ./sbt ++${SCALA_VERSION}! testJVM
- <<: *save_cache
testJVM211: &testJVM211
steps:
- checkout
- <<: *load_cache
- <<: *install_jdk
- run:
name: Run Redis
command: docker-compose up
background: true
- run:
name: Run tests
command: ./sbt ++${SCALA_VERSION}! testJVM211
- <<: *save_cache
release: &release
......@@ -131,42 +145,42 @@ jobs:
- <<: *jdk_8
test_211_jdk8:
<<: *test
<<: *testJVM211
<<: *machine_ubuntu
environment:
- <<: *scala_211
- <<: *jdk_8
test_212_jdk8:
<<: *test
<<: *testJVM
<<: *machine_ubuntu
environment:
- <<: *scala_212
- <<: *jdk_8
test_213_jdk8:
<<: *test
<<: *testJVM
<<: *machine_ubuntu
environment:
- <<: *scala_213
- <<: *jdk_8
test_211_jdk11:
<<: *test
<<: *testJVM211
<<: *machine_ubuntu
environment:
- <<: *scala_211
- <<: *jdk_11
test_212_jdk11:
<<: *test
<<: *testJVM
<<: *machine_ubuntu
environment:
- <<: *scala_212
- <<: *jdk_11
test_213_jdk11:
<<: *test
<<: *testJVM
<<: *machine_ubuntu
environment:
- <<: *scala_213
......
package zio.redis
import cats.effect.{ ContextShift, IO => CatsIO, Timer }
import zio.BootstrapRuntime
import zio.internal.Platform
import scala.concurrent.ExecutionContext
object BenchmarkRuntime extends BootstrapRuntime {
implicit val cs: ContextShift[CatsIO] = CatsIO.contextShift(ExecutionContext.global)
implicit val timer: Timer[CatsIO] = CatsIO.timer(ExecutionContext.global)
override val platform: Platform = Platform.benchmark
final val RedisHost = "127.0.0.1"
final val RedisPort = 6379
}
package zio.redis
import java.util.concurrent.TimeUnit
import org.openjdk.jmh.annotations._
import zio.ZIO
@State(Scope.Thread)
@BenchmarkMode(Array(Mode.Throughput))
@OutputTimeUnit(TimeUnit.SECONDS)
@Measurement(iterations = 15, timeUnit = TimeUnit.SECONDS, time = 3)
@Warmup(iterations = 15, timeUnit = TimeUnit.SECONDS, time = 3)
@Fork(3)
class PutBenchmarks {
import BenchmarkRuntime._
@Param(Array("500"))
private var count: Int = _
private var items: List[String] = _
@Setup(Level.Trial)
def setup(): Unit =
items = (0 to count).toList.map(_.toString)
@Benchmark
def laserdisc(): Unit = {
import _root_.laserdisc._
import _root_.laserdisc.{ all => cmd }
import _root_.laserdisc.auto._
import _root_.laserdisc.fs2._
import cats.instances.list._
import cats.syntax.foldable._
RedisClient
.to(RedisHost, RedisPort)
.use(c => items.traverse_(i => c.send(cmd.set(Key.unsafeFrom(i), i))))
.unsafeRunSync
}
@Benchmark
def redis4cats(): Unit = {
import cats.effect.IO
import cats.instances.list._
import cats.syntax.foldable._
import dev.profunktor.redis4cats.Redis
import dev.profunktor.redis4cats.effect.Log.NoOp._
Redis[IO]
.utf8(s"redis://$RedisHost:$RedisPort")
.use(c => items.traverse_(i => c.set(i, i)))
.unsafeRunSync
}
@Benchmark
def zio(): Unit = {
val effect = ZIO
.foreach_(items)(i => set(i, i, None, None, None))
.provideLayer(RedisExecutor.live(RedisHost, RedisPort).orDie)
unsafeRun(effect)
}
}
......@@ -7,8 +7,7 @@ inThisBuild(
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
developers := List(
Developer("jdegoes", "John De Goes", "john@degoes.net", url("https://degoes.net")),
Developer("mijicd", "Dejan Mijic", "dmijic@acm.org", url("https://github.com/mijicd")),
Developer("paulpdaniels", "Paul Daniels", "paulpdaniels@gmail.com", url("https://github.com/paulpdaniels"))
Developer("mijicd", "Dejan Mijic", "dmijic@acm.org", url("https://github.com/mijicd"))
),
pgpPassphrase := sys.env.get("PGP_PASSWORD").map(_.toArray),
pgpPublicRing := file("/tmp/public.asc"),
......@@ -21,10 +20,19 @@ inThisBuild(
addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt")
addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck")
addCommandAlias("testJVM", ";redis/test;benchmarks/test:compile")
addCommandAlias("testJVM211", ";redis/test")
lazy val redis =
lazy val root =
project
.in(file("."))
.settings(skip in publish := true)
.aggregate(redis, benchmarks)
lazy val redis =
project
.in(file("redis"))
.enablePlugins(BuildInfoPlugin)
.settings(stdSettings("zio-redis"))
.settings(buildInfoSettings("zio.redis"))
.settings(
......@@ -35,4 +43,17 @@ lazy val redis =
),
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.enablePlugins(BuildInfoPlugin)
lazy val benchmarks =
project
.in(file("benchmarks"))
.dependsOn(redis)
.enablePlugins(JmhPlugin)
.settings(
crossScalaVersions -= Scala211,
skip in publish := true,
libraryDependencies ++= Seq(
"dev.profunktor" %% "redis4cats-effects" % "0.10.0",
"io.laserdisc" %% "laserdisc-fs2" % "0.4.0"
)
)
......@@ -25,9 +25,10 @@ object BuildHelper {
incOptions ~= (_.withLogRecompileOnMacro(false))
)
private val Scala211 = "2.11.12"
private val Scala212 = "2.12.10"
private val Scala213 = "2.13.1"
val Scala211 = "2.11.12"
val Scala212 = "2.12.10"
val Scala213 = "2.13.1"
private val SilencerVersion = "1.4.4"
private val StdOpts =
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册