Skip to content

Commit 75a625d

Browse files
committed
Generator for correctness almost complete.
Still some differences between algorithms for different methods, so results aren't actually identical yet. (May need to intercept sets differently also.)
1 parent 733a035 commit 75a625d

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

benchmark/src/main/scala/bench/CodeGen.scala

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package bench.codegen
22

33
import scala.util._
4-
import scala.util.control.NonFatal
4+
import control.NonFatal
55

66
object Generator {
77
val annotated = "arr ish lst* ils* que* stm* trs* vec arb ars ast* mhs lhs* prq* muq* wra jix jln".split(' ')
8+
val allops = Seq(("OnInt", "I", "sum/psum trig/ptrig fmc/pfmc mdtc"), ("OnString", "S", "nbr/pnbr htrg/phtrg fmc/pfmc mdtc"))
9+
def parsefs(fs: String) = fs.split(' ').map(_.split('/') match { case Array(x) => (x, None); case Array(x,y) => (x, Some(y)) })
10+
811
val names = annotated.map(_.takeWhile(_.isLetter))
9-
val nojnames = names.filterNot(_ startsWith "j")
12+
val nojname = names.filterNot(_ startsWith "j").toSet
13+
val parname = annotated.filter(_.forall(_.isLetter)).toSet
14+
val sqnname = names.filterNot(parname).toSet union names.filterNot(nojname).toSet
1015

1116
def writeTo(f: java.io.File)(pr: (String => Unit) => Unit): Either[Throwable, Unit] = {
1217
try {
@@ -35,24 +40,39 @@ object Generator {
3540
pr(""" val wrong = new collection.mutable.ArrayBuffer[String]""")
3641
pr(""" def check[A](a1: A, a2: => A, msg: String) {""")
3742
pr(""" var t = System.nanoTime""")
38-
pr(""" if (!CloseEnough(a1, { val ans = a2; t = System.nanoTime - t; ans})) wrong += msg""")
43+
pr(""" if (!CloseEnough(a1, { val ans = a2; t = System.nanoTime - t; ans}))""")
44+
pr(""" wrong += msg""")
3945
pr(""" if (t > 2000000000) wrong += "Slow " + msg""")
4046
pr(""" }""")
47+
pr( s" val m = (new bench.generate.Things(${sayArrayI(sizes)})).N;" )
48+
allops.foreach{ case (o, t, fs) =>
49+
names.foreach{ n =>
50+
pr( s" { // Scope for operations $o collection $n")
4151
pr( s" val x = new bench.generate.Things(${sayArrayI(sizes)})" )
42-
pr(""" for (i <- 0 until x.N) {""")
43-
pr(""" val si = OnInt.sum(x.arr.cI(i))""")
44-
nojnames.tail.foreach{ n =>
45-
pr( s" check(si, OnInt.sum(x.$n.cI(i)), ${q}cI sum $n ${q}+i.toString)")
46-
}
47-
nojnames.foreach{ n =>
48-
pr( s" check(si, OnInt.sum(x.$n.iI(i)), ${q}iI sum $n ${q}+i.toString)")
49-
}
50-
annotated.foreach{ m =>
51-
val n = m.takeWhile(_.isLetter)
52-
val c = if (m contains "*") "ssI" else "spI"
53-
pr( s" check(si, OnInt.sum(x.$n.$c(i)), ${q}$c sum $n ${q}+i.toString)")
54-
}
52+
parsefs(fs).foreach{ case (f, pf) =>
53+
pr(""" for (i <- 0 until m) {""")
54+
pr( s" val z = $o.$f(x.arr.c$t(i))")
55+
if (nojname(n)) {
56+
pr( s" check(z, $o.$f(x.$n.c$t(i)), ${q}c$t $f $n ${q}+i.toString)");
57+
pr( s" check(z, $o.$f(x.$n.i$t(i)), ${q}i$t $f $n ${q}+i.toString)")
58+
}
59+
if (sqnname(n)) {
60+
pr( s" check(z, $o.$f(x.$n.ss$t(i)), ${q}ss$t $f $n ${q}+i.toString)")
61+
if (nojname(n)) {
62+
pr( s" check(z, $o.$f(x.$n.zs$t(i)), ${q}zs$t $f $n ${q}+i.toString)")
63+
}
64+
}
65+
if (parname(n)) {
66+
pr( s" check(z, $o.$f(x.$n.sp$t(i)), ${q}sp$t $f $n ${q}+i.toString)")
67+
if (nojname(n)) {
68+
pr( s" check(z, $o.$f(x.$n.zp$t(i)), ${q}zp$t $f $n ${q}+i.toString)")
69+
}
70+
}
5571
pr( s" }")
72+
}
73+
pr( s" } // End scope for operations $o collection $n")
74+
}
75+
}
5676
pr(""" wrong.foreach(println)""")
5777
pr(""" if (wrong.nonEmpty) sys.exit(1) """)
5878
pr(""" }""")

benchmark/src/main/scala/bench/CollectionSource.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ package object generate {
261261

262262
class JlnThings(val sizes: Array[Int]) extends AbstractThings[java.util.LinkedList]("java.util.LinkedList") {}
263263

264-
class Things(sizes: Array[Int] = Array(0, 1, 2, 5, 7, 15, 16, 32, 33, 64, 129, 256, 1023, 2914, 7151, 20000, 50000, 200000)) {
264+
class Things(sizes: Array[Int] = Array(0, 1, 2, 5, 7, 15, 16, 32, 33, 64, 129, 256, 1023, 2914, 7151/*, 20000, 50000, 200000*/)) {
265265
def N = sizes.length
266266
lazy val arr = new ArrThings(sizes)
267267
lazy val ish = new IshThings(sizes)

0 commit comments

Comments
 (0)