Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.twitter.algebird.benchmark

import com.twitter.algebird.mutable.{BloomFilter, BloomFilterAggregator, MutableBF}
import com.twitter.algebird.benchmark.BloomFilterCreateBenchmark.createRandomString
import org.openjdk.jmh.annotations._

object MutableBloomFilterCreateBenchmark {

@State(Scope.Benchmark)
class BloomFilterState {
@Param(Array("100", "1000", "10000"))
var nbrOfElements: Int = 0

@Param(Array("0.001", "0.01"))
var falsePositiveRate: Double = 0

var randomStrings: Seq[String] = _

@Setup(Level.Trial)
def setup(): Unit =
randomStrings = createRandomString(nbrOfElements, 10)

}
}
class MutableBloomFilterBenchmark {

import MutableBloomFilterCreateBenchmark._

@Benchmark
def createMutableBloomFilter(bloomFilterState: BloomFilterState): MutableBF[String] = {
val bfMonoid = BloomFilter[String](bloomFilterState.nbrOfElements, bloomFilterState.falsePositiveRate)
val bf = bfMonoid.create(bloomFilterState.randomStrings: _*)
bf
}

@Benchmark
def createMutableBloomFilterUsingFold(bloomFilterState: BloomFilterState): MutableBF[String] = {
val bfMonoid = BloomFilter[String](bloomFilterState.nbrOfElements, bloomFilterState.falsePositiveRate)
val bf = bloomFilterState.randomStrings.foldLeft(bfMonoid.zero) {
case (filter, string) => filter += string
}
bf
}

@Benchmark
def createMutableBloomFilterAggregator(bloomFilterState: BloomFilterState): MutableBF[String] = {
val bfMonoid = BloomFilter[String](bloomFilterState.nbrOfElements, bloomFilterState.falsePositiveRate)
val bfAggregator = BloomFilterAggregator(bfMonoid)

val bf = bloomFilterState.randomStrings.aggregate(bfAggregator.monoid.zero)(_ += _, _ ++= _)
bf
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.twitter.algebird
package benchmark

import org.openjdk.jmh.annotations._

object MutableBloomFilterQueryBenchmark {

@State(Scope.Benchmark)
class BloomFilterState {

@Param(Array("100", "1000", "10000"))
var nbrOfElements: Int = 0

@Param(Array("0.001", "0.01"))
var falsePositiveRate: Double = 0

var bf: mutable.MutableBF[String] = _

@Setup(Level.Trial)
def setup(): Unit = {
val randomStrings =
BloomFilterCreateBenchmark.createRandomString(nbrOfElements, 10)
bf = mutable
.BloomFilter[String](nbrOfElements, falsePositiveRate)
.create(randomStrings: _*)
}
}
}

class MutableBloomFilterQueryBenchmark {
import MutableBloomFilterQueryBenchmark._

@Benchmark
def queryBloomFilter(bloomFilterState: BloomFilterState): ApproximateBoolean =
bloomFilterState.bf.contains("1")
}
Loading