diff options
author | Rocky Madden <git@rockymadden.com> | 2014-01-02 13:47:43 -0700 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2014-01-02 13:47:43 -0700 |
commit | 49de854bb464f1be37fbb27f942b9b65e52df751 (patch) | |
tree | 6c9a27ac1264648f67eba9c8707fa87d3dc5b3cd /core/src/benchmark/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricBenchmark.scala | |
parent | 42b990a1523a68717afcbdbc2cc4968c041451ec (diff) | |
download | stringmetric-49de854bb464f1be37fbb27f942b9b65e52df751.tar.gz stringmetric-49de854bb464f1be37fbb27f942b9b65e52df751.tar.bz2 stringmetric-49de854bb464f1be37fbb27f942b9b65e52df751.zip |
Moved from gradle to sbt.
Diffstat (limited to 'core/src/benchmark/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricBenchmark.scala')
-rwxr-xr-x | core/src/benchmark/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricBenchmark.scala | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/core/src/benchmark/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricBenchmark.scala b/core/src/benchmark/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricBenchmark.scala new file mode 100755 index 0000000..5df27fb --- /dev/null +++ b/core/src/benchmark/scala/com/rockymadden/stringmetric/similarity/DiceSorensenMetricBenchmark.scala @@ -0,0 +1,48 @@ +package com.rockymadden.stringmetric.similarity + +import com.google.caliper.Param +import com.rockymadden.stringmetric.{CaliperBenchmark, CaliperRunner} +import scala.util.Random + +final class DiceSorensenMetricBenchmark extends CaliperBenchmark { + @Param(Array("0", "1", "2", "4", "8", "16")) + var length: Int = _ + + var string1: String = _ + var charArray1: Array[Char] = _ + var string2: String = _ + var charArray2: Array[Char] = _ + + override protected def setUp() { + @annotation.tailrec + def random(l: Int, ps: String = null): String = + if (l == 0) "" + else { + val s = Random.alphanumeric.take(l).mkString + + if (ps == null || s != ps) s + else random(l, ps) + } + + string1 = random(length) + string2 = random(length, string1) + charArray1 = string1.toCharArray + charArray2 = string2.toCharArray + } + + def timeCompareWithDifferentCharArrays(reps: Int) = run(reps) { + DiceSorensenMetric(2).compare(charArray1, charArray2) + } + + def timeCompareWithDifferentStrings(reps: Int) = run(reps) { + DiceSorensenMetric(2).compare(string1, string2) + } + + def timeCompareWithIdenticalCharArrays(reps: Int) = run(reps) { + DiceSorensenMetric(2).compare(charArray1, charArray1) + } + + def timeCompareWithIdenticalStrings(reps: Int) = run(reps) { + DiceSorensenMetric(2).compare(string1, string1) + } +} |