Commit b3e0c6d0 authored by Noric Couderc's avatar Noric Couderc
Browse files

Refactoring: FeatureSet is a list

We don't need to supply a list, the FeatureSet IS a List

Makes the code much cleaner.
parent 96548841
......@@ -43,7 +43,7 @@ class EventSetBuilder : FeatureVisitor {
private var eventSet : EventSet? = null
override fun visitFeatureSet(featureSet: FeatureSet) {
for (f in featureSet.features) {
for (f in featureSet) {
f.accept(this)
}
......
......@@ -33,7 +33,7 @@ class Experiment(val numberIterations : Int,
}
fun run() : List<Result> {
if (features.features.isEmpty()) { return listOf() }
if (features.isEmpty()) { return listOf() }
val iterations = getIterations()
......@@ -105,7 +105,7 @@ class Experiment(val numberIterations : Int,
}
override fun visitFeatureSet(featureSet: FeatureSet) {
for (f in featureSet.features) {
for (f in featureSet) {
f.accept(this)
}
}
......
......@@ -178,7 +178,13 @@ fun defaultNormalize(f : Feature) : Feature? {
* (For example: Create ONE papi event set for the
* whole of the features)
*/
class FeatureSet(val features : List<Feature>) {
class FeatureSet(vararg features : Feature) : ArrayList<Feature>() {
init {
for (f in features) {
this.add(f)
}
}
fun accept(visitor : FeatureVisitor) {
visitor.visitFeatureSet(this)
}
......@@ -186,7 +192,7 @@ class FeatureSet(val features : List<Feature>) {
fun brainyFeatures() : FeatureSet {
return FeatureSet(
se.lth.cs.listOf(PAPICounter("PAPI_BR_MSP"),
PAPICounter("PAPI_BR_MSP"),
PAPICounter("PAPI_L1_DCM"),
FeatureRatio(
PAPICounter("PAPI_L1_DCM"),
......@@ -205,5 +211,5 @@ fun brainyFeatures() : FeatureSet {
CostFeature(OperationType.SEARCH),
CostFeature(OperationType.ITERATE),
CostFeature(OperationType.INSERT),
CostFeature(OperationType.DELETE)))
CostFeature(OperationType.DELETE))
}
......@@ -35,7 +35,7 @@ class EventSetBuilderTest {
PAPICounter("PAPI_L1_DCM")
)
val spec = FeatureSet(counters)
val spec = FeatureSet(*counters.toTypedArray())
val builder = EventSetBuilder()
spec.accept(builder)
......@@ -48,9 +48,9 @@ class EventSetBuilderTest {
val features = listOf(
CostFeature(OperationType.INSERT),
PAPICounter("PAPI_L1_DCM")
)
).toTypedArray()
val spec = FeatureSet(features)
val spec = FeatureSet(*features)
val builder = EventSetBuilder()
spec.accept(builder)
......@@ -76,9 +76,9 @@ class EventSetBuilderTest {
CostFeature(OperationType.INSERT),
CostFeature(OperationType.DELETE)
)
)
).toTypedArray()
val spec = FeatureSet(features)
val spec = FeatureSet(*features)
val builder = EventSetBuilder()
spec.accept(builder)
......@@ -97,9 +97,9 @@ class EventSetBuilderTest {
fun testEventBuildInvalidEvents() {
val features = listOf(
PAPICounter("PAPI_L1_DCM"),
PAPICounter("PAPI_L1_DCA"))
PAPICounter("PAPI_L1_DCA")).toTypedArray()
val spec = FeatureSet(features)
val spec = FeatureSet(*features)
// Oh no! empty list of PAPI events!
val builder = EventSetBuilder()
......
......@@ -16,7 +16,7 @@ class ExperimentTest {
fun testExperimentNoFeatures() {
val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())
val exp = Experiment(10, bench, FeatureSet(listOf()), runner)
val exp = Experiment(10, bench, FeatureSet(), runner)
val results = exp.run()
Assertions.assertTrue(results.isEmpty())
......@@ -26,9 +26,7 @@ class ExperimentTest {
fun testExperiment1() {
val bench = BCBenchmarkPackage.LIST(1234, 100, 0, ArrayList<Int>())
val exp = Experiment(10, bench,
FeatureSet(
listOf(PAPICounter("PAPI_TOT_CYC"))
),
FeatureSet(PAPICounter("PAPI_TOT_CYC")),
runner
)
......@@ -59,11 +57,9 @@ class ExperimentTest {
val exp = Experiment(10, bench,
FeatureSet(
listOf(
PAPICounter("PAPI_TOT_INS"),
costPerDelete,
cacheMissRate
)
PAPICounter("PAPI_TOT_INS"),
costPerDelete,
cacheMissRate
),
runner
)
......
......@@ -20,10 +20,8 @@ class SyntheticBenchmarkExperimentPrinterTest {
fun testNoBenchmarks() {
val writer = StringWriter()
val features = FeatureSet(
listOf(
PAPICounter("PAPI_TOT_CYC"),
MethodInvocations("java.util.List.add", "JAVA-STANDARD-FORMAT")
)
PAPICounter("PAPI_TOT_CYC"),
MethodInvocations("java.util.List.add", "JAVA-STANDARD-FORMAT")
)
val printer = SyntheticBenchmarkExperimentPrinter(writer,
"",
......@@ -41,11 +39,9 @@ class SyntheticBenchmarkExperimentPrinterTest {
fun testListBenchmarks() {
val writer = StringWriter()
val features = FeatureSet(
listOf(
PAPICounter("PAPI_TOT_CYC"),
CostFeature(OperationType.INSERT),
MethodInvocations("runAdd", "JAVA-STANDARD-FORMAT")
)
PAPICounter("PAPI_TOT_CYC"),
CostFeature(OperationType.INSERT),
MethodInvocations("runAdd", "JAVA-STANDARD-FORMAT")
)
val printer = SyntheticBenchmarkExperimentPrinter(writer,
"",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment