@@ -4,14 +4,24 @@ import scala.util._
4
4
import control .NonFatal
5
5
6
6
object Generator {
7
- 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)) })
7
+ // Trailing * means that a collection is not expected to work efficiently in parallel
8
+ // Trailing ! means that a collection is not expected to maintain original order
9
+ val annotated = " arr ish! lst* ils*! que* stm* trs*! vec arb ars ast* mhs! lhs*! prq*! muq* wra jix jln" .split(' ' )
10
+
11
+ // Parallel version if any appears after /
12
+ // Trailing ! means that collection must maintain original order (i.e. don't use if collection is marked !)
13
+ val allops = Seq ((" OnInt" , " I" , " sum/psum trig/ptrig fmc/pfmc mdtc!" ), (" OnString" , " S" , " nbr/pnbr htrg/phtrg fmc/pfmc mdtc!" ))
14
+
15
+ def parsefs (fs : String ) = fs.split(' ' ).map(_.split('/' ) match {
16
+ case Array (x) => (x.takeWhile(_.isLetter), None , x contains " !" )
17
+ case Array (x,y) => (x.takeWhile(_.isLetter), Some (y.takeWhile(_.isLetter)), (x+ y) contains " !" )
18
+ })
10
19
11
20
val names = annotated.map(_.takeWhile(_.isLetter))
12
21
val nojname = names.filterNot(_ startsWith " j" ).toSet
13
- val parname = annotated.filter(_.forall (_.isLetter)).toSet
22
+ val parname = annotated.filterNot(_ contains " * " ).map(_.takeWhile (_.isLetter)).toSet
14
23
val sqnname = names.filterNot(parname).toSet union names.filterNot(nojname).toSet
24
+ val ordname = annotated.filterNot(_ contains " !" ).map(_.takeWhile(_.isLetter)).toSet
15
25
16
26
def writeTo (f : java.io.File )(pr : (String => Unit ) => Unit ): Either [Throwable , Unit ] = {
17
27
try {
@@ -30,53 +40,53 @@ object Generator {
30
40
val q = " \" "
31
41
if (target.exists) throw new java.io.IOException (" Generator will not write to existing file: " + target.getPath)
32
42
writeTo(target){ pr =>
33
- pr(""" package bench.test""" )
34
- pr(""" """ )
35
- pr(""" import bench.generate._, bench.operate._, bench.generate.EnableIterators._""" )
36
- pr(""" import scala.compat.java8.StreamConverters._""" )
37
- pr(""" """ )
38
- pr(""" object Agreement {""" )
39
- pr(""" def run() {""" )
40
- pr(""" val wrong = new collection.mutable.ArrayBuffer[String]""" )
41
- pr(""" def check[A](a1: A, a2: => A, msg: String) {""" )
42
- pr(""" var t = System.nanoTime""" )
43
- pr(""" if (!CloseEnough(a1, { val ans = a2; t = System.nanoTime - t; ans}))""" )
44
- pr(""" wrong += msg""" )
45
- pr(""" if (t > 2000000000) wrong += "Slow " + msg""" )
46
- pr(""" }""" )
47
- pr( s " val m = (new bench.generate.Things( ${sayArrayI(sizes)})).N; " )
43
+ pr( """ package bench.test""" )
44
+ pr( """ """ )
45
+ pr( """ import bench.generate._, bench.operate._, bench.generate.EnableIterators._""" )
46
+ pr( """ import scala.compat.java8.StreamConverters._""" )
47
+ pr( """ """ )
48
+ pr( """ object Agreement {""" )
49
+ pr( """ def run() {""" )
50
+ pr( """ val wrong = new collection.mutable.ArrayBuffer[String]""" )
51
+ pr( """ def check[A](a1: A, a2: => A, msg: String) {""" )
52
+ pr( """ var t = System.nanoTime""" )
53
+ pr( """ if (!CloseEnough(a1, { val ans = a2; t = System.nanoTime - t; ans}))""" )
54
+ pr( """ wrong += msg""" )
55
+ pr( """ if (t > 2000000000) wrong += "Slow " + msg""" )
56
+ pr( """ }""" )
57
+ pr( s " val m = (new bench.generate.Things( ${sayArrayI(sizes)})).N; " )
48
58
allops.foreach{ case (o, t, fs) =>
49
59
names.foreach{ n =>
50
- pr( s " { // Scope for operations $o collection $n" )
51
- pr( s " val x = new bench.generate.Things( ${sayArrayI(sizes)}) " )
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) " )
60
+ pr( s " { // Scope for operations $o collection $n" )
61
+ pr( s " val x = new bench.generate.Things( ${sayArrayI(sizes)}) " )
62
+ parsefs(fs).foreach{ case (f, pf, ord) =>
63
+ if (ordname(n) || ! ord) {
64
+ pr( """ for (i <- 0 until m) {""" )
65
+ pr( s " val z = $o. $f(x.arr.c $t(i)) " )
66
+ if (nojname(n)) {
67
+ pr( s " check(z, $o. $f(x. $n.c $t(i)), ${q}c $t $f $n ${q}+i.toString) " );
68
+ pr( s " check(z, $o. $f(x. $n.i $t(i)), ${q}i $t $f $n ${q}+i.toString) " )
63
69
}
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) " )
70
+ if (sqnname(n)) {
71
+ pr( s " check(z, $o. $f(x. $n.ss $t(i)), ${q}ss $t $f $n ${q}+i.toString) " )
72
+ if (nojname(n))
73
+ pr( s " check(z, $o. $f(x. $n.zs $t(i)), ${q}zs $t $f $n ${q}+i.toString) " )
74
+ }
75
+ if (parname(n) && pf.isDefined) {
76
+ pr( s " check(z, $o. $f(x. $n.sp $t(i)), ${q}sp $t $f $n ${q}+i.toString) " )
77
+ if (nojname(n))
78
+ pr( s " check(z, $o. $f(x. $n.zp $t(i)), ${q}zp $t $f $n ${q}+i.toString) " )
69
79
}
80
+ pr( s " } " )
70
81
}
71
- pr( s " } " )
72
82
}
73
- pr( s " } // End scope for operations $o collection $n" )
83
+ pr( s " } // End scope for operations $o collection $n" )
74
84
}
75
85
}
76
- pr(""" wrong.foreach(println)""" )
77
- pr(""" if (wrong.nonEmpty) sys.exit(1) """ )
78
- pr(""" }""" )
79
- pr(""" }""" )
86
+ pr( """ wrong.foreach(println)""" )
87
+ pr( """ if (wrong.nonEmpty) sys.exit(1) """ )
88
+ pr( """ }""" )
89
+ pr( """ }""" )
80
90
} match {
81
91
case Left (t) => println(" Did not successfully write file: " + target.getPath); throw t
82
92
case _ =>
0 commit comments