Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (37 sloc) 1.18 KB
package org.scalax.asuna.circe.encoder.test
import java.util.concurrent.TimeUnit
import io.circe.Encoder
import org.openjdk.jmh.annotations._
import org.scalax.asuna.implements.circe.encoder.CirceHelper
@BenchmarkMode(Array(Mode.Throughput)) // 测试方法平均执行时间
@OutputTimeUnit(TimeUnit.SECONDS) // 输出结果的时间粒度为微秒
@State(Scope.Thread) // 每个测试线程一个实例
class AbcTest extends CirceHelper {
import upickle.default._
import upickle.default.{ReadWriter => RW, macroRW}
implicit lazy val rw1: RW[Foo] = macroRW
implicit lazy val rw2: RW[Bar] = macroRW
val rawCirceEncoder = {
import io.circe.generic.semiauto._
implicit val a1: Encoder[Foo] = deriveEncoder
deriveEncoder[Bar]
}
val a3 = {
implicit val a1 = valEncoder.effect(valEncoder.singleModel[Foo](Ghi).compile).encoder
valEncoder.effect(valEncoder.singleModel[Bar](Ghi).compile).encoder
}
val model: Bar = Model.bar
@Benchmark
def upickleTest = {
write(model)
}
object Ghi
@Benchmark
def asunaCirceTest = {
a3(model).noSpaces
}
@Benchmark
def rawCirceTest = {
rawCirceEncoder(model).noSpaces
}
}