Skip to content

Commit 970278c

Browse files
committed
Create a bunch of classes for benchmarking.
Code is quite general, since compiler can be tricked into expanding everything the way it needs to be.
1 parent e77ca87 commit 970278c

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

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

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,106 @@ package object generate {
6565
def s[CC](cc: CC)(implicit streamize: CC => MakesParallelStream[String, Stream[String]]) =
6666
streamize(cc).parStream
6767
}
68+
69+
trait GenThingsOf[CC[_]] {
70+
def title: String
71+
def sizes: Array[Int]
72+
}
73+
74+
trait IntThingsOf[CC[_]] extends GenThingsOf[CC] {
75+
implicit def myCBFi: CanBuildFrom[Nothing, Int, CC[Int]]
76+
// Base collection
77+
val cI = sizes.map(n => Coll.i[CC](n))
78+
// Iterator
79+
def iI(j: Int)(implicit x: CC[Int] => Iterator[Int]) = x(cI(j))
80+
// Steppers (second letter--s = sequential, p = parallel)
81+
def tsI(j: Int)(implicit x: CC[Int] => MakesIntSeqStepper) = Sstep i cI(j)
82+
def tpI(j: Int)(implicit x: CC[Int] => MakesIntStepper) = Pstep i cI(j)
83+
// Streams
84+
def ssI(j: Int)(implicit x: CC[Int] => MakesSequentialStream[java.lang.Integer, IntStream]) = Sstream i cI(j)
85+
def spI(j: Int)(implicit x: CC[Int] => MakesParallelStream[java.lang.Integer, IntStream]) = Pstream i cI(j)
86+
// Streams via steppers
87+
def zsI(j: Int)(implicit x: CC[Int] => MakesIntSeqStepper) = SsStream i cI(j)
88+
def zpI(j: Int)(implicit x: CC[Int] => MakesIntStepper) = PsStream i cI(j)
89+
}
90+
91+
trait StringThingsOf[CC[_]] extends GenThingsOf[CC] {
92+
implicit def myCBFs: CanBuildFrom[Nothing, String, CC[String]]
93+
// Base collection
94+
val cS = sizes.map(n => Coll.s[CC](n))
95+
// Iterator
96+
def iS(j: Int)(implicit x: CC[String] => Iterator[String]) = x(cS(j))
97+
// Steppers (second letter--s = sequential, p = parallel)
98+
def tsS(j: Int)(implicit x: CC[String] => MakesAnySeqStepper[String]) = Sstep s cS(j)
99+
def tpS(j: Int)(implicit x: CC[String] => MakesAnyStepper[String]) = Pstep s cS(j)
100+
// Streams
101+
def ssS(j: Int)(implicit x: CC[String] => MakesSequentialStream[String, Stream[String]]) = Sstream s cS(j)
102+
def spS(j: Int)(implicit x: CC[String] => MakesParallelStream[String, Stream[String]]) = Pstream s cS(j)
103+
// Streams via steppers
104+
def zsS(j: Int)(implicit x: CC[String] => MakesAnySeqStepper[String]) = SsStream s cS(j)
105+
def zpS(j: Int)(implicit x: CC[String] => MakesAnyStepper[String]) = PsStream s cS(j)
106+
}
107+
108+
trait ThingsOf[CC[_]] extends IntThingsOf[CC] with StringThingsOf[CC] {}
109+
110+
abstract class AbstractThings[CC[_]](val title: String)(
111+
implicit
112+
outerCBFi: CanBuildFrom[Nothing, Int, CC[Int]],
113+
outerCBFs: CanBuildFrom[Nothing, String, CC[String]]
114+
)
115+
extends ThingsOf[CC] {
116+
implicit def myCBFi = outerCBFi
117+
implicit def myCBFs = outerCBFs
118+
}
119+
120+
class ArrThings(val sizes: Array[Int]) extends AbstractThings[Array]("Array") {}
121+
122+
class IshThings(val sizes: Array[Int]) extends AbstractThings[collection.immutable.HashSet]("immutable.HashSet") {}
123+
124+
class LstThings(val sizes: Array[Int]) extends AbstractThings[List]("List") {}
125+
126+
class IlsThings(val sizes: Array[Int]) extends AbstractThings[collection.immutable.ListSet]("immutable.ListSet") {}
127+
128+
class QueThings(val sizes: Array[Int]) extends AbstractThings[collection.immutable.Queue]("immutable.Queue") {}
129+
130+
class StmThings(val sizes: Array[Int]) extends AbstractThings[collection.immutable.Stream]("immutable.Stream") {}
131+
132+
class TrsThings(val sizes: Array[Int]) extends AbstractThings[collection.immutable.TreeSet]("immutable.TreeSet") {}
133+
134+
class VecThings(val sizes: Array[Int]) extends AbstractThings[Vector]("Vector") {}
135+
136+
class ArbThings(val sizes: Array[Int]) extends AbstractThings[collection.mutable.ArrayBuffer]("mutable.ArrayBuffer") {}
137+
138+
class ArsThings(val sizes: Array[Int]) extends AbstractThings[collection.mutable.ArraySeq]("mutable.ArraySeq") {}
139+
140+
class AstThings(val sizes: Array[Int]) extends AbstractThings[collection.mutable.ArrayStack]("mutable.ArrayStack") {}
141+
142+
class MhsThings(val sizes: Array[Int]) extends AbstractThings[collection.mutable.HashSet]("mutable.HashSet") {}
143+
144+
class LhsThings(val sizes: Array[Int]) extends AbstractThings[collection.mutable.LinkedHashSet]("mutable.LinkedHashSet") {}
145+
146+
class PrqThings(val sizes: Array[Int]) extends AbstractThings[collection.mutable.PriorityQueue]("mutable.PriorityQueue") {}
147+
148+
class MuqThings(val sizes: Array[Int]) extends AbstractThings[collection.mutable.Queue]("mutable.Queue") {}
149+
150+
class WraThings(val sizes: Array[Int]) extends AbstractThings[collection.mutable.WrappedArray]("mutable.WrappedArray") {}
151+
152+
class Things(sizes: Array[Int] = Array(0, 1, 2, 5, 7, 15, 16, 32, 33, 64, 129, 256, 1023, 2914, 7151, 50000, 200000, 1000000)) {
153+
lazy val arr = new ArrThings(sizes)
154+
lazy val ish = new IshThings(sizes)
155+
lazy val lst = new LstThings(sizes)
156+
lazy val ils = new IlsThings(sizes)
157+
lazy val que = new QueThings(sizes)
158+
lazy val stm = new StmThings(sizes)
159+
lazy val trs = new TrsThings(sizes)
160+
lazy val vec = new VecThings(sizes)
161+
lazy val arb = new ArbThings(sizes)
162+
lazy val ars = new ArsThings(sizes)
163+
lazy val ast = new AstThings(sizes)
164+
lazy val mhs = new MhsThings(sizes)
165+
lazy val lhs = new LhsThings(sizes)
166+
lazy val prq = new PrqThings(sizes)
167+
lazy val muq = new MuqThings(sizes)
168+
lazy val wra = new WraThings(sizes)
169+
}
68170
}

0 commit comments

Comments
 (0)