当前位置: 首页>>代码示例>>Scala>>正文


Scala Benchmark类代码示例

本文整理汇总了Scala中org.openjdk.jmh.annotations.Benchmark的典型用法代码示例。如果您正苦于以下问题:Scala Benchmark类的具体用法?Scala Benchmark怎么用?Scala Benchmark使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Benchmark类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: ActorPathValidationBenchmark

//设置package包名称以及导入依赖的类
package akka.actor

import java.util.concurrent.TimeUnit

import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.BenchmarkMode
import org.openjdk.jmh.annotations.Fork
import org.openjdk.jmh.annotations.Measurement
import org.openjdk.jmh.annotations.Mode
import org.openjdk.jmh.annotations.OutputTimeUnit
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State
import org.openjdk.jmh.annotations.Warmup


@Fork(2)
@State(Scope.Benchmark)
@BenchmarkMode(Array(Mode.Throughput))
@Warmup(iterations = 5)
@Measurement(iterations = 10)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
class ActorPathValidationBenchmark {

  final val a = "actor-1"
  final val s = "687474703a2f2f74686566727569742e636f6d2f26683d37617165716378357926656e" * 100

  final val ElementRegex = """(?:[-\w:@&=+,.!~*'_;]|%\p{XDigit}{2})(?:[-\w:@&=+,.!~*'$_;]|%\p{XDigit}{2})*""".r

  //  @Benchmark // blows up with stack overflow, we know
  def old7000: Option[List[String]] = ElementRegex.unapplySeq(s)

  @Benchmark
  def handLoop7000: Boolean = ActorPath.isValidPathElement(s)

  @Benchmark
  def oldActor_1: Option[List[String]] = ElementRegex.unapplySeq(a)

  @Benchmark
  def handLoopActor_1: Boolean = ActorPath.isValidPathElement(a)

} 
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:42,代码来源:ActorPathValidationBenchmark.scala

示例2: MsgPackToArrayBench

//设置package包名称以及导入依赖的类
package knot.msgpack

import java.util.concurrent.TimeUnit

import org.msgpack.core.MessagePack
import org.openjdk.jmh.annotations.{Benchmark, Measurement, Scope, State}

@State(Scope.Benchmark)
@Measurement(timeUnit = TimeUnit.MILLISECONDS)
class MsgPackToArrayBench {

  val encoder = MsgPackEncoder()
  val packer = MessagePack.newDefaultBufferPacker()

  @Benchmark
  def toArray_knot() = {
    go_encoder()
    val r = encoder.toArray()
    require(r.size > 0)
    encoder.clear()
  }

  @Benchmark
  def toArray_org() = {
    go_packer()
    val r = packer.toByteArray()
    require(r.size > 0)
    packer.clear()
  }

  private def go_encoder() = {
    encoder
      .put(false)
      .put(true)
      .put(Int.MinValue)
      .put(Int.MaxValue)
      .put(Short.MinValue)
      .put(Short.MaxValue)
      .put(Long.MinValue)
      .put(Long.MaxValue)
      .put(Float.MinValue)
      .put(Float.MaxValue)
      .flush()
  }

  private def go_packer() = {
    packer
      .packBoolean(false)
      .packBoolean(true)
      .packInt(Int.MinValue)
      .packInt(Int.MaxValue)
      .packShort(Short.MinValue)
      .packShort(Short.MaxValue)
      .packLong(Long.MinValue)
      .packLong(Long.MaxValue)
      .packFloat(Float.MinValue)
      .packFloat(Float.MaxValue)
      .flush()
  }
} 
开发者ID:defvar,项目名称:knot,代码行数:61,代码来源:MsgPackToArrayBench.scala

示例3: MsgPackMapBench

//设置package包名称以及导入依赖的类
package knot.msgpack

import java.util.concurrent.TimeUnit

import org.msgpack.core.MessagePack
import org.msgpack.value.ValueFactory.{newInteger, newMap}
import org.openjdk.jmh.annotations.{Benchmark, Measurement, Scope, State}

@State(Scope.Benchmark)
@Measurement(timeUnit = TimeUnit.MILLISECONDS)
class MsgPackMapBench {
  val msgbuffer = MsgPackEncoder()
  val packer = MessagePack.newDefaultBufferPacker()

  val bufferMap = Map((1, 10.toShort), (2, 20.toShort))
  val packerMap = newMap(
    newInteger(1), newInteger(10.toShort),
    newInteger(2), newInteger(20.toShort))

  @Benchmark
  def map_knot() = {
    msgbuffer.put(bufferMap).flush()
    msgbuffer.clear()
  }

  @Benchmark
  def map_org() = {
    packer.packValue(packerMap).flush()
    packer.clear()
  }
} 
开发者ID:defvar,项目名称:knot,代码行数:32,代码来源:MsgPackMapBench.scala

示例4: ByteNodeBench

//设置package包名称以及导入依赖的类
package knot.data

import java.util.concurrent.TimeUnit

import knot.data.buffers.Unsafe
import org.openjdk.jmh.annotations.{Benchmark, Measurement, Scope, State}

@State(Scope.Benchmark)
@Measurement(timeUnit = TimeUnit.MILLISECONDS)
class ByteNodeBench {

  val bigNode = ByteNode.wrap(Array.ofDim[Byte](1024 * 4 * 4))
  val bigVector = Array.ofDim[Byte](1024 * 4 * 4).toVector

  val array = Array.ofDim[Byte](1024 * 4)

  @Benchmark
  def arrayCopy_clone(): Unit = {
    val r = array.clone()
    require(r.size == array.size)
  }

  @Benchmark
  def arrayCopy_unsafeCopy(): Unit = {
    val dst = Array.ofDim[Byte](1024 * 4)
    Unsafe.instance.copyMemory(array, Unsafe.ARRAY_BYTE_BASE_OFFSET, dst, Unsafe.ARRAY_BYTE_BASE_OFFSET, dst.length)
    require(dst.size == array.size)
  }

  @Benchmark
  def slice_ByteNode(): Unit = {
    val r = bigNode.slice(2000, 4000)
    require(r.size == 2000)
  }

  @Benchmark
  def slice_Vector(): Unit = {
    val r = bigVector.slice(2000, 4000)
    require(r.size == 2000)
  }
} 
开发者ID:defvar,项目名称:knot,代码行数:42,代码来源:ByteNodeBench.scala

示例5: SeqParBench

//设置package包名称以及导入依赖的类
package eleutheros.bench

import cats.arrow.FunctionK
import cats.instances.option._
import cats.syntax.apply._
import cats.syntax.flatMap._
import cats.syntax.functor._
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}

@State(Scope.Benchmark)
class SeqParBench {

  @Benchmark
  def eleutherosIotaSeqPar: Option[Int] = { 
    import eleutheros.SeqParExample._
    import SeqPar._

    val one = SeqPar.pure[Option, Int](1)
    val two = SeqPar.liftF[Option, Int](Some(2))
    val f: Int => SeqPar[Option, Int] = i => SeqPar.pure(i + 1)

    val xyz: SeqPar[Option, Int] = for {
      x <- one  // 1
      y <- two  // 2
      z <- f(y).map2(two)(_ + _) // (2 + 1) + 2 = 5
    } yield x + y + z // 1 + 2 + 5 = 8

    val result: Option[Int] = SeqPar.foldMap(xyz)(FunctionK.id)

    result
  }

  @Benchmark
  def freestyleFreeS: Option[Int] = {
    import cats.~>
    import freestyle._

    val one = FreeS.pure[Option, Int](1)
    val two = FreeS.liftFA[Option, Int](Some(2))
    val f: Int => FreeS[Option, Int] = i => FreeS.pure(i + 1)

    val xyz = for {
      x <- one  // 1
      y <- two  // 2
      z <- f(y).map2(two)(_ + _) // (2 + 1) + 2 = 5
    } yield x + y + z // 1 + 2 + 5 = 8


    implicit val fk: Option ~> Option = FunctionK.id[Option]
    val result: Option[Int] = xyz.interpret[Option]

    result
  }

} 
开发者ID:peterneyens,项目名称:eleutheros,代码行数:56,代码来源:SeqParBench.scala

示例6: BackupRequestFilterBenchmark

//设置package包名称以及导入依赖的类
package com.twitter.finagle.exp

import com.twitter.conversions.time._
import com.twitter.finagle.Service
import com.twitter.finagle.benchmark.StdBenchAnnotations
import com.twitter.finagle.stats.NullStatsReceiver
import com.twitter.util.{Await, JavaTimer, Future}
import java.util.concurrent.atomic.AtomicInteger
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}


@State(Scope.Benchmark)
class BackupRequestFilterBenchmark extends StdBenchAnnotations {

  private[this] val i = new AtomicInteger()
  private[this] val timer = new JavaTimer(true) // we need high resolution
  private[this] val Response = Future.value(1000)

  private[this] val backupReqFilter = new BackupRequestFilter[String, Int](
    95,
    1.second,
    timer,
    NullStatsReceiver,
    1.minute
  )

  private[this] val svc =
    backupReqFilter.andThen(Service.const(Response))

  private[this] val sometimesSleepySvc =
    backupReqFilter.andThen(Service.mk[String, Int] { _ =>
      if (i.incrementAndGet() % 100 == 0)
        Thread.sleep(2)
      Response
    })

  @Benchmark
  def noBackups(): Int =
    Await.result(svc(""))

  @Benchmark
  def onePercentBackups(): Int =
    Await.result(sometimesSleepySvc(""))

} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:46,代码来源:BackupRequestFilterBenchmark.scala

示例7: HelloClient

//设置package包名称以及导入依赖的类
package com.twitter.finagle.thrift

import com.twitter.finagle.ThriftMux
import com.twitter.finagle.benchmark.StdBenchAnnotations
import com.twitter.finagle.benchmark.thriftscala._
import com.twitter.util.{Await, Future}
import com.twitter.finagle.param
import com.twitter.finagle.stats.NullStatsReceiver
import com.twitter.finagle.tracing.NullTracer
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}


@State(Scope.Benchmark)
class HelloClient extends StdBenchAnnotations {
  val svc: Hello[Future] = ThriftMux.client
    .configured(param.Tracer(NullTracer))
    .configured(param.Stats(NullStatsReceiver))
    .newIface[Hello.FutureIface]("localhost:1234")

  @Benchmark
  def helloClient(): String = {
    Await.result(svc.echo("asdf"))
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:25,代码来源:HelloClient.scala

示例8: ServiceFactoryCacheBenchmark

//设置package包名称以及导入依赖的类
package com.twitter.finagle.factory

import com.twitter.finagle.{ClientConnection, Service, ServiceFactory}
import com.twitter.finagle.benchmark.StdBenchAnnotations
import com.twitter.finagle.stats.NullStatsReceiver
import com.twitter.util.Future
import java.util.Random
import java.util.concurrent.atomic.AtomicInteger
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}

// ko todo: run with some concurrency
@State(Scope.Benchmark)
class ServiceFactoryCacheBenchmark extends StdBenchAnnotations {
  import ServiceFactoryCacheBenchmark._

  @Benchmark
  def apply(state: CacheState): Future[Service[Int, Int]] =
    state.cache(state.nextKey(), state.conn)

}

object ServiceFactoryCacheBenchmark {

  private[this] val newFactory: Int => ServiceFactory[Int, Int] = key => {
    val svc = Service.mk[Int, Int] { in => Future.value(key + in) }
    ServiceFactory.const(svc)
  }

  // use 12 inputs into a cache of size 8 so as to get some misses
  private[this] val MaxCacheSize = 8
  private[this] val MaxInput = 12

  @State(Scope.Benchmark)
  class CacheState {
    val conn: ClientConnection = ClientConnection.nil

    val cache = new ServiceFactoryCache[Int, Int, Int](
      newFactory,
      NullStatsReceiver,
      MaxCacheSize)

    def nextKey(): Int = {
      val offset = pos.incrementAndGet()
      inputs(offset % inputs.length)
    }

    private[this] val pos: AtomicInteger = new AtomicInteger(0)

    private[this] val inputs: Array[Int] = {
      val rng = new Random(12345L)
      Array.fill(1024) { rng.nextInt(MaxInput) }
    }
  }

} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:56,代码来源:ServiceFactoryCacheBenchmark.scala

示例9: ParserUtilsBenchmark

//设置package包名称以及导入依赖的类
package com.twitter.finagle.memcached.util

import com.twitter.finagle.benchmark.StdBenchAnnotations
import com.twitter.finagle.memcached.util.ParserUtilsBenchmark.Position
import java.nio.charset.StandardCharsets.UTF_8
import org.jboss.netty.buffer.{ChannelBuffer, ChannelBuffers}
import org.openjdk.jmh.annotations.{State, Benchmark, Scope}
import scala.util.Random

// ./sbt 'project finagle-benchmark' 'jmh:run ParserUtilsBenchmark'
class ParserUtilsBenchmark extends StdBenchAnnotations {

  @Benchmark
  def isDigits(pos: Position): Boolean = {
    val idx = pos.i % pos.inputs.length
    pos.i += 1
    ParserUtils.isDigits(pos.inputs(idx))
  }

}

object ParserUtilsBenchmark {

  private val size = 100000
  private val rnd = new Random(69230L) // just to give us consistent values

  private val numbers: Seq[ChannelBuffer] = Seq.fill(size) {
    ChannelBuffers.copiedBuffer(rnd.nextInt().toString, UTF_8)
  }
  private val strings: Seq[ChannelBuffer] = Seq.fill(size) {
    ChannelBuffers.copiedBuffer(rnd.nextString(5), UTF_8)
  }

  private val _inputs =
    (numbers ++ strings).toIndexedSeq

  @State(Scope.Thread)
  class Position {
    var i = 0

    def inputs: IndexedSeq[ChannelBuffer] = ParserUtilsBenchmark._inputs
  }

} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:45,代码来源:ParserUtilsBenchmark.scala

示例10: EmptyStringBenchmark

//设置package包名称以及导入依赖的类
package com.komanov.stringformat.jmh

import org.openjdk.jmh.annotations.Benchmark

class EmptyStringBenchmark extends BenchmarkBase {

  @Benchmark
  def baseline: String = {
    ""
  }

  @Benchmark
  def sInterpolator: String = {
    s""
  }

  @Benchmark
  def sfiInterpolator: String = {
    import com.komanov.stringformat.macros.MacroConcat._
    sfi""
  }
}

class ConstStringBenchmark extends BenchmarkBase {

  @Benchmark
  def baseline: String = {
    "abc"
  }

  @Benchmark
  def sInterpolator: String = {
    s"abc"
  }

  @Benchmark
  def sfiInterpolator: String = {
    import com.komanov.stringformat.macros.MacroConcat._
    sfi"abc"
  }
} 
开发者ID:dkomanov,项目名称:scala-string-format,代码行数:42,代码来源:SimpleBenchmarks.scala

示例11: NewStringBenchmarkData

//设置package包名称以及导入依赖的类
package com.komanov.stringformat.jmh

import com.komanov.stringformat.FastStringFactory
import org.openjdk.jmh.annotations.Benchmark

object NewStringBenchmarkData {
  val chars = new Array[Char](1006)
  val sb = new java.lang.StringBuilder(chars.length)
    .append(chars)
}

class NewStringBenchmark extends BenchmarkBase {

  @Benchmark
  def baseline: String = {
    ""
  }

  @Benchmark
  def newString: String = {
    new String(NewStringBenchmarkData.chars)
  }

  @Benchmark
  def fastString: String = {
    FastStringFactory.fastNewString(NewStringBenchmarkData.chars)
  }

  @Benchmark
  def sbToString: String = {
    NewStringBenchmarkData.sb.toString
  }

  @Benchmark
  def fastSb: String = {
    FastStringFactory.fastNewString(NewStringBenchmarkData.sb)
  }

} 
开发者ID:dkomanov,项目名称:scala-string-format,代码行数:40,代码来源:NewStringBenchmark.scala

示例12: StringBuilderBenchmark

//设置package包名称以及导入依赖的类
package com.komanov.stringformat.jmh

import org.openjdk.jmh.annotations.Benchmark

class StringBuilderBenchmark extends BenchmarkBase {

  @Benchmark
  def javaStringBuilder: String = {
    new java.lang.StringBuilder()
      .append("abc")
      .append("def")
      .toString
  }

  @Benchmark
  def javaStringBuilder2: String = {
    new java.lang.StringBuilder()
      .append("string______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________495")
      .append("string______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________495")
      .toString
  }

  @Benchmark
  def scalaStringBuilder: String = {
    new scala.collection.mutable.StringBuilder()
      .append("abc")
      .append("def")
      .toString
  }

  @Benchmark
  def scalaStringBuilder2: String = {
    new scala.collection.mutable.StringBuilder()
      .append("string______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________495")
      .append("string______________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________495")
      .toString
  }

} 
开发者ID:dkomanov,项目名称:scala-string-format,代码行数:40,代码来源:StringBuilderBenchmark.scala

示例13: Benchmarks

//设置package包名称以及导入依赖的类
package de.heikoseeberger.hex

import org.openjdk.jmh.annotations.Benchmark

object Benchmarks {
  val bytes: Array[Byte] = Array.iterate(1.toByte, 1024)(b => (b + 1).toByte)
}

class Benchmarks {
  import Benchmarks._

  @Benchmark
  def benchmarkNaive(): Unit = {
    import Functional._
    bytes.toHex
  }

  @Benchmark
  def benchmarkImperative(): Unit = {
    import Imperative._
    bytes.toHex
  }
} 
开发者ID:hseeberger,项目名称:hex,代码行数:24,代码来源:Benchmarks.scala

示例14: StatBenchmark

//设置package包名称以及导入依赖的类
package com.twitter.finagle.stats

import com.twitter.util.{Await, Future, StdBenchAnnotations}
import java.util.concurrent.TimeUnit
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}

// ./sbt 'project util-benchmark' 'jmh:run StatBenchmark'
@State(Scope.Benchmark)
class StatBenchmark extends StdBenchAnnotations {

  private[this] val nullStat = NullStatsReceiver.stat("null")

  private[this] val aFuture = Future.value("hello")

  @Benchmark
  def time: String = {
    Stat.time(nullStat, TimeUnit.MILLISECONDS) {
      "hello"
    }
  }

  @Benchmark
  def timeFuture: String = {
    Await.result(Stat.timeFuture(nullStat, TimeUnit.MILLISECONDS) {
      aFuture
    })
  }

} 
开发者ID:lanshuijuntuan,项目名称:Java.util,代码行数:30,代码来源:StatBenchmark.scala

示例15: BufConcatBenchmark

//设置package包名称以及导入依赖的类
package com.twitter.io

import com.twitter.util.StdBenchAnnotations
import java.nio.ByteBuffer
import org.openjdk.jmh.annotations.{Benchmark, Param, Scope, State}

// run via:
// ./sbt 'project util-benchmark' 'jmh:run BufConcatBenchmark'
@State(Scope.Benchmark)
class BufConcatBenchmark extends StdBenchAnnotations {

  @Param(Array("1", "5", "10", "20", "40"))
  var concats: Int = _

  val bytes = Array[Byte](1, 2, 3, 4)

  val byteArrayBuf = Buf.ByteArray.Owned(bytes)
  val byteBufferBuf = Buf.ByteBuffer.Owned(ByteBuffer.wrap(bytes))
  val compositeBuf = byteArrayBuf.slice(0, bytes.length / 2)
    .concat(byteArrayBuf.slice(bytes.length / 2, bytes.length))

  private[this] def concatN(n: Int, buf: Buf): Buf = {
    var acc = buf
    var i = 0
    while (i < n) {
      i += 1
      acc = acc.concat(buf)
    }

    acc
  }

  @Benchmark
  def concatByteBufferBuf(): Buf =
    concatN(concats, byteBufferBuf)

  @Benchmark
  def concatByteArrayBuf(): Buf =
    concatN(concats, byteArrayBuf)

  @Benchmark
  def concatCompositeBuf(): Buf =
    concatN(concats, compositeBuf)
} 
开发者ID:lanshuijuntuan,项目名称:Java.util,代码行数:45,代码来源:BufConcatBenchmark.scala


注:本文中的org.openjdk.jmh.annotations.Benchmark类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。