-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use HashMap for literals look up (#2960)
- Loading branch information
Showing
7 changed files
with
146 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version = 1.8.3 | ||
sbt.version = 1.10.7 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0") | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0") | ||
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0") | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.2.0") | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.14.0") | ||
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.4") |
77 changes: 77 additions & 0 deletions
77
zio-http-benchmarks/src/main/scala/zio/http/benchmark/RoutesBenchmark.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package zio.http.benchmark | ||
|
||
import java.util.concurrent.TimeUnit | ||
|
||
import scala.util.Random | ||
|
||
import zio.{Runtime, Unsafe, ZIO} | ||
|
||
import zio.http.endpoint.Endpoint | ||
import zio.http.{Handler, Method, Request, Routes} | ||
|
||
import org.openjdk.jmh.annotations._ | ||
|
||
@State(Scope.Thread) | ||
@BenchmarkMode(Array(Mode.Throughput)) | ||
@OutputTimeUnit(TimeUnit.SECONDS) | ||
class RoutesBenchmark { | ||
|
||
val REPEAT_N = 1000 | ||
|
||
val paths = ('a' to 'z').inits.map(_.mkString).toList.reverse.tail | ||
|
||
val routes = Routes.fromIterable(paths.map(p => Endpoint(Method.GET / p).out[Unit].implementHandler(Handler.unit))) | ||
|
||
val requests = paths.map(p => Request.get(p)) | ||
|
||
def request: Request = requests(Random.nextInt(requests.size)) | ||
val smallDataRequests = Array.fill(REPEAT_N)(request) | ||
|
||
def unsafeRun[E, A](zio: ZIO[Any, E, A]): Unit = Unsafe.unsafe { implicit unsafe => | ||
Runtime.default.unsafe | ||
.run(zio.unit) | ||
.getOrThrowFiberFailure() | ||
} | ||
|
||
val paths2 = ('b' to 'z').inits.map(_.mkString).toList.reverse.tail | ||
|
||
val routes2 = Routes.fromIterable(paths2.map(p => Endpoint(Method.GET / p).out[Unit].implementHandler(Handler.unit))) | ||
|
||
val requests2 = requests ++ paths2.map(p => Request.get(p)) | ||
|
||
def request2: Request = requests2(Random.nextInt(requests2.size)) | ||
|
||
val smallDataRequests2 = Array.fill(REPEAT_N)(request2) | ||
|
||
val routes3 = Routes( | ||
Endpoint(Method.GET / "api").out[Unit].implementHandler(Handler.unit), | ||
Endpoint(Method.GET / "ui").out[Unit].implementHandler(Handler.unit), | ||
) | ||
|
||
val requests3 = Array.fill(REPEAT_N)(List(Request.get("api"), Request.get("ui"))(Random.nextInt(2))) | ||
|
||
@Benchmark | ||
def benchmarkSmallDataZioApi(): Unit = | ||
for (r <- smallDataRequests) routes.isDefinedAt(r) | ||
|
||
@Benchmark | ||
def benchmarkSmallDataZioApi2(): Unit = | ||
for (r <- smallDataRequests2) routes2.isDefinedAt(r) | ||
|
||
@Benchmark | ||
def notFound1(): Unit = | ||
for (_ <- 1 to REPEAT_N) { | ||
routes.isDefinedAt(Request.get("not-found")) | ||
} | ||
|
||
@Benchmark | ||
def notFound2(): Unit = | ||
for (_ <- 1 to REPEAT_N) { | ||
routes2.isDefinedAt(Request.get("not-found")) | ||
} | ||
|
||
@Benchmark | ||
def benchmarkSmallDataZioApi3(): Unit = | ||
for (r <- requests3) routes3.isDefinedAt(r) | ||
|
||
} |
This file contains 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
This file contains 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