summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRocky Madden <git@rockymadden.com>2012-11-18 19:54:49 -0700
committerRocky Madden <git@rockymadden.com>2012-11-18 19:54:49 -0700
commitdfe88eb56a95a0bc88ece493a3d6590f07f07590 (patch)
tree7304f22630b70039ca348c60d15034628386c20a /core
parent42f22328e3ae7ca3abb9f4496cc1b9a1598eaa6f (diff)
downloadstringmetric-dfe88eb56a95a0bc88ece493a3d6590f07f07590.tar.gz
stringmetric-dfe88eb56a95a0bc88ece493a3d6590f07f07590.tar.bz2
stringmetric-dfe88eb56a95a0bc88ece493a3d6590f07f07590.zip
Created refined NYSIIS benchmarks.
Diffstat (limited to 'core')
-rwxr-xr-xcore/source/benchmark/scala/org/hashtree/stringmetric/phonetic/RefinedNysiisAlgorithmBenchmark.scala28
-rwxr-xr-xcore/source/benchmark/scala/org/hashtree/stringmetric/phonetic/RefinedNysiisMetricBenchmark.scala51
2 files changed, 79 insertions, 0 deletions
diff --git a/core/source/benchmark/scala/org/hashtree/stringmetric/phonetic/RefinedNysiisAlgorithmBenchmark.scala b/core/source/benchmark/scala/org/hashtree/stringmetric/phonetic/RefinedNysiisAlgorithmBenchmark.scala
new file mode 100755
index 0000000..9303f9c
--- /dev/null
+++ b/core/source/benchmark/scala/org/hashtree/stringmetric/phonetic/RefinedNysiisAlgorithmBenchmark.scala
@@ -0,0 +1,28 @@
+package org.hashtree.stringmetric.phonetic
+
+import com.google.caliper.Param
+import org.hashtree.stringmetric.{ CaliperBenchmark, CaliperRunner }
+import scala.util.Random
+
+final class RefinedNysiisAlgorithmBenchmark extends CaliperBenchmark {
+ @Param(Array("0", "1", "2", "4", "8", "16"))
+ var length: Int = _
+
+ var string: String = _
+ var charArray: Array[Char] = _
+
+ override protected def setUp() {
+ string = Random.alphanumeric.filter(_ > '9').take(length).mkString
+ charArray = string.toCharArray
+ }
+
+ def timeComputeWithCharArray(reps: Int) = run(reps) {
+ RefinedNysiisAlgorithm.compute(charArray)
+ }
+
+ def timeComputeWithString(reps: Int) = run(reps) {
+ RefinedNysiisAlgorithm.compute(string)
+ }
+}
+
+object RefinedNysiisAlgorithmBenchmark extends CaliperRunner(classOf[RefinedNysiisAlgorithmBenchmark]) \ No newline at end of file
diff --git a/core/source/benchmark/scala/org/hashtree/stringmetric/phonetic/RefinedNysiisMetricBenchmark.scala b/core/source/benchmark/scala/org/hashtree/stringmetric/phonetic/RefinedNysiisMetricBenchmark.scala
new file mode 100755
index 0000000..dd9c926
--- /dev/null
+++ b/core/source/benchmark/scala/org/hashtree/stringmetric/phonetic/RefinedNysiisMetricBenchmark.scala
@@ -0,0 +1,51 @@
+package org.hashtree.stringmetric.phonetic
+
+import com.google.caliper.Param
+import org.hashtree.stringmetric.{ CaliperBenchmark, CaliperRunner }
+import scala.annotation.tailrec
+import scala.util.Random
+
+final class RefinedNysiisMetricBenchmark 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.filter(_ > '9').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) {
+ RefinedNysiisMetric.compare(charArray1, charArray2)
+ }
+
+ def timeCompareWithDifferentStrings(reps: Int) = run(reps) {
+ RefinedNysiisMetric.compare(string1, string2)
+ }
+
+ def timeCompareWithIdenticalCharArrays(reps: Int) = run(reps) {
+ RefinedNysiisMetric.compare(charArray1, charArray1)
+ }
+
+ def timeCompareWithIdenticalStrings(reps: Int) = run(reps) {
+ RefinedNysiisMetric.compare(string1, string1)
+ }
+}
+
+object RefinedNysiisMetricBenchmark extends CaliperRunner(classOf[RefinedNysiisMetricBenchmark]) \ No newline at end of file