diff options
author | Rocky Madden <git@rockymadden.com> | 2013-01-11 09:34:58 -0700 |
---|---|---|
committer | Rocky Madden <git@rockymadden.com> | 2013-01-12 10:02:19 -0700 |
commit | 0066c5410b7cc48512891aff7d1ceb9a38c20004 (patch) | |
tree | 60bc623a1aa953538d5f941d41a1cb908bdad63c /core/source/benchmark/scala/com/rockymadden | |
parent | 56b500ff29e12d5d63abded42d1124259f14583a (diff) | |
download | stringmetric-0066c5410b7cc48512891aff7d1ceb9a38c20004.tar.gz stringmetric-0066c5410b7cc48512891aff7d1ceb9a38c20004.tar.bz2 stringmetric-0066c5410b7cc48512891aff7d1ceb9a38c20004.zip |
Created Ratcliff/Obershelp benchmark.
Diffstat (limited to 'core/source/benchmark/scala/com/rockymadden')
-rwxr-xr-x | core/source/benchmark/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricBenchmark.scala | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/core/source/benchmark/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricBenchmark.scala b/core/source/benchmark/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricBenchmark.scala new file mode 100755 index 0000000..d4217cf --- /dev/null +++ b/core/source/benchmark/scala/com/rockymadden/stringmetric/similarity/RatcliffObershelpMetricBenchmark.scala @@ -0,0 +1,51 @@ +package com.rockymadden.stringmetric.similarity + +import com.google.caliper.Param +import com.rockymadden.stringmetric.{ CaliperBenchmark, CaliperRunner } +import scala.annotation.tailrec +import scala.util.Random + +final class RatcliffObershelpMetricBenchmark 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() { + @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) { + RatcliffObershelpMetric.compare(charArray1, charArray2) + } + + def timeCompareWithDifferentStrings(reps: Int) = run(reps) { + RatcliffObershelpMetric.compare(string1, string2) + } + + def timeCompareWithIdenticalCharArrays(reps: Int) = run(reps) { + RatcliffObershelpMetric.compare(charArray1, charArray1) + } + + def timeCompareWithIdenticalStrings(reps: Int) = run(reps) { + RatcliffObershelpMetric.compare(string1, string1) + } +} + +object RatcliffObershelpMetricBenchmark extends CaliperRunner(classOf[RatcliffObershelpMetricBenchmark]) |