-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
142 additions
and
49 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
61 changes: 61 additions & 0 deletions
61
algebird-caliper/src/test/scala/com/twitter/algebird/caliper/QTreeBenchmark.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,61 @@ | ||
package com.twitter.algebird.caliper | ||
|
||
import com.twitter.algebird._ | ||
import scala.util.Random | ||
import com.twitter.bijection._ | ||
|
||
import java.util.concurrent.Executors | ||
import com.twitter.algebird.util._ | ||
import com.google.caliper.{ Param, SimpleBenchmark } | ||
import java.nio.ByteBuffer | ||
|
||
import scala.math._ | ||
|
||
class OldQTreeSemigroup[A: Monoid](k: Int) extends QTreeSemigroup[A](k) { | ||
override def sumOption(items: TraversableOnce[QTree[A]]) = | ||
if (items.isEmpty) None | ||
else Some(items.reduce(plus)) | ||
} | ||
|
||
class QTreeBenchmark extends SimpleBenchmark { | ||
var qtree: QTreeSemigroup[Long] = _ | ||
var oldqtree: QTreeSemigroup[Long] = _ | ||
|
||
@Param(Array("5", "10", "12")) | ||
val depthK: Int = 0 | ||
|
||
@Param(Array("100", "10000")) | ||
val numElements: Int = 0 | ||
|
||
var inputData: Seq[QTree[Long]] = _ | ||
|
||
override def setUp { | ||
qtree = new QTreeSemigroup[Long](depthK) | ||
oldqtree = new OldQTreeSemigroup(depthK) | ||
|
||
val rng = new Random("qtree".hashCode) | ||
|
||
inputData = (0L until numElements).map { _ => | ||
QTree(rng.nextInt(1000).toLong) | ||
} | ||
} | ||
|
||
def timeSumOption(reps: Int): Int = { | ||
var dummy = 0 | ||
while (dummy < reps) { | ||
qtree.sumOption(inputData) | ||
dummy += 1 | ||
} | ||
dummy | ||
} | ||
|
||
/* | ||
def timeOldSumOption(reps: Int): Int = { | ||
var dummy = 0 | ||
while (dummy < reps) { | ||
oldqtree.sumOption(inputData) | ||
dummy += 1 | ||
} | ||
dummy | ||
} */ | ||
} |
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