• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Benchmark类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: KeyHasherBenchmark

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

import com.twitter.util.StdBenchAnnotations
import org.openjdk.jmh.annotations.{Benchmark, Level, Param, Scope, Setup, State}
import scala.util.Random

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

  private[this] var inputs: Array[String] = _

  @Param(Array("50"))
  var len = 50

  private[this] val N = 1024

  @Setup(Level.Trial)
  def setupTrial(): Unit = {
    val rnd = new Random(515144)
    inputs = Array.fill(N) { rnd.nextString(len) }
  }

  private[this] var i = 0

  @Setup(Level.Iteration)
  def setupIter(): Unit =
    i = 0

  private[this] val keyHasher = KeyHasher.KETAMA

  @Benchmark
  def hashStringKetama: Long = {
    i += 1
    val bytes = inputs(i % N).getBytes("UTF-8")
    keyHasher.hashKey(bytes)
  }

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


示例17: MurmurHash3Benchmark

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

import java.nio.ByteBuffer

import sandbox.hashing.{YonikMurmurHash3, CassandraMurmurHash, AlgebirdMurmurHash128}
import sandbox.hashing.YonikMurmurHash3.LongPair
import com.yahoo.sketches.hash.{MurmurHash3 => yMurmurHash3}
import com.google.common.hash.Hashing
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}
import scala.util.hashing.{MurmurHash3 => ScalaMurmurHash3}
import com.clearspring.analytics.hash.{MurmurHash => StreamLibMurmurHash}

@State(Scope.Benchmark)
class MurmurHash3Benchmark {

  val key = Range(0, 64).map(_.toByte).toArray

  @Benchmark
  def javaVersion() = {
    YonikMurmurHash3.murmurhash3_x64_128(key, 0, key.length, 0, new LongPair)
  }

  @Benchmark
  def scalaVersion() = {
    MurmurHash3Generic.murmurhash3_x64_128(key, 0, key.length, 0)
  }

  val guavaMurmur = Hashing.murmur3_128()

  @Benchmark
  def guavaVersion() = {
    guavaMurmur.hashBytes(key, 0, key.length)
  }

  @Benchmark
  def cassandraVersion() = {
    CassandraMurmurHash.hash3_x64_128(ByteBuffer.wrap(key), 0, key.length, 0)
  }

  val algebirdMurmur = AlgebirdMurmurHash128(0)

  @Benchmark
  def algebirdVersion() = {
    algebirdMurmur.apply(key)
  }

  @Benchmark
  def yahooVersion() = {
    yMurmurHash3.hash(key, 0)
  }

  @Benchmark
  def scalaStdlibVersion() = {
    ScalaMurmurHash3.arrayHash(key, 0)
  }

  @Benchmark
  def streamLibVersion() = {
    StreamLibMurmurHash.hash(key)
  }
} 
开发者ID:alexandrnikitin,项目名称:bloom-filter-scala,代码行数:62,代码来源:MurmurHash3Benchmark.scala


示例18: MurmurHash3GenericBenchmark

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

import org.openjdk.jmh.annotations.{Benchmark, Scope, State}
import sandbox.hashing.MurmurHash3

@State(Scope.Benchmark)
class MurmurHash3GenericBenchmark {

  val key = Range(0, 64).map(_.toByte).toArray

  @Benchmark
  def scalaVersion() = {
    MurmurHash3.murmurhash3_x64_128(key, 0, key.length, 0)
  }

  @Benchmark
  def genericVersion() = {
    MurmurHash3Generic.murmurhash3_x64_128(key, 0, key.length, 0)
  }
} 
开发者ID:alexandrnikitin,项目名称:bloom-filter-scala,代码行数:21,代码来源:MurmurHash3GenericBenchmark.scala


示例19: UnsafeBitArrayBenchmark

//设置package包名称以及导入依赖的类
package bloomfilter

import java.util.BitSet

import bloomfilter.mutable.UnsafeBitArray
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}
import sandbox.bloomfilter.mutable.ChronicleBitArray

@State(Scope.Benchmark)
class UnsafeBitArrayBenchmark {

  private val numberOfBits = Int.MaxValue

  val unsafeBits = new UnsafeBitArray(numberOfBits.toLong)
  val bitsSet = new BitSet(numberOfBits)
  val chronicle = new ChronicleBitArray(numberOfBits.toLong)

  @Benchmark
  def getUnsafe() = {
    unsafeBits.get(1)
    unsafeBits.get(10)
    unsafeBits.get(100)
    unsafeBits.get(1000)
    unsafeBits.get(10000)
    unsafeBits.get(100000)
    unsafeBits.get(1000000)
  }

  @Benchmark
  def getBitSet() = {
    bitsSet.get(1)
    bitsSet.get(10)
    bitsSet.get(100)
    bitsSet.get(1000)
    bitsSet.get(10000)
    bitsSet.get(100000)
    bitsSet.get(1000000)
  }

  @Benchmark
  def getChronicle() = {
    chronicle.get(1)
    chronicle.get(10)
    chronicle.get(100)
    chronicle.get(1000)
    chronicle.get(10000)
    chronicle.get(100000)
    chronicle.get(1000000)
  }


} 
开发者ID:alexandrnikitin,项目名称:bloom-filter-scala,代码行数:53,代码来源:UnsafeBitArrayBenchmark.scala


示例20: Scato

//设置package包名称以及导入依赖的类
package scato
package benchmarks

import org.openjdk.jmh.annotations.{Benchmark, BenchmarkMode, Fork, Mode}

object Scato {
  import Prelude._
  import transformers.State

  def mkState[F[_]](xs: F[Int])(f: Long => (Unit, Long))(implicit F: Traversable[F]): State[Long, Unit] =
    xs.foldLeft(State.pure[Long, Unit](()))((s, _) => s.flatMap(_ => State.state(f)))

  def run[F[_]](xs: F[Int])(f: Long => (Unit, Long))(implicit F: Traversable[F]): (Unit, Long) =
    State.run(mkState(xs)(f))(0)
}

object Scalaz {
  import scalaz._
  import scalaz.State
  import scalaz.Free._
  import scalaz.syntax.traverse._

  def mkState[F[_]](xs: F[Int])(f: Long => (Long, Unit))(implicit F: Traverse[F]) =
    xs.foldLeft(State.state[Long, Unit](()).liftF)((s, _) => s.flatMap(_ => State[Long, Unit](s => f(s)).liftF))

  def run[F[_]](xs: F[Int])(f: Long => (Long, Unit))(implicit F: Traverse[F]): (Long, Unit) =
    mkState(xs)(f).foldRun(0L)((a,b) => b(a))
}

@Fork(1)
@BenchmarkMode(Array(Mode.Throughput))
class Interpreters {
  import Data._

  def f0(i: Long): (Unit, Long) = ((), i + 1)
  def f1(i: Long): (Long, Unit) = (i + 1, ())

  @Benchmark def scalaz = {
    import _root_.scalaz.std.AllInstances._
    Scalaz.run(xs)(f1 _)
  }

  @Benchmark def scato  = Scato.run(xs)(f0 _)
} 
开发者ID:aloiscochard,项目名称:scato,代码行数:45,代码来源:Interpreters.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala ScriptEngine类代码示例发布时间:2022-05-23
下一篇:
Scala MongoDBObject类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap