Gitlab service upgraded. Please report any problems to dl_gitadmin@cs.lth.se

Commit dd571d7c authored by Noric Couderc's avatar Noric Couderc

Changed parameterization of benchmarks for lists

- Added parameters to the benchmark, did not rely on application generator
    - size: Size of the application, in number of method calls
    - seed: The seed to use for the random number generator for applications.
    - datastructure: The data structure to use.

This is done so that we can leverage JMH handling of parameters for running the
benchmarks.

- Added a blackhole object to avoid dead code elimination of the benchmark
  results

Changed return type of the benchmark() method to return to the blackhole object
parent 4fd1d0ae
package se.lth.cs;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import se.lth.cs.ApplicationGeneration.ListApplicationGenerator;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class ApplicationBenchmark {
@State(Scope.Thread)
public static class BenchmarkState {
@Param({"0"})
@Param({"0", "1", "2", "3"})
public int seed;
@Param({"1000"})
@Param({"100", "1000"})
public int applicationSize;
private List<Application> applications;
{
ApplicationRunner runner = new ApplicationRunner();
try {
List<TrainingSetValue> phase1Set = runner.runBenchmarks(
new ListApplicationGenerator().createApplications(0, 2, 10000)
);
applications = phase1Set.stream().map(TrainingSetValue::getApplication).collect(Collectors.toList());
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
@Param({"LinkedList", "ArrayList", "Vector"})
public String datastructureName;
public Application application;
public Application currentApplication;
@Setup(Level.Trial)
public void doSetup() {
application = applications.get(seed);
// application = new ListApplication(seed, applicationSize, new ArrayList<>());
List<Integer> datastructure;
switch (datastructureName) {
case "LinkedList": datastructure = new LinkedList<>(); break;
case "ArrayList": datastructure = new ArrayList<>(); break;
case "Vector": datastructure = new Vector<>(); break;
default: datastructure = new ArrayList<>(); break;
}
currentApplication = new ListApplication(seed, applicationSize, datastructure);
}
}
@Benchmark
public void ListApplicationBenchmark(BenchmarkState state) throws InvocationTargetException, IllegalAccessException, InstantiationException {
state.application.benchmark();
public void ListApplicationBenchmark(BenchmarkState state, Blackhole blackhole) throws InvocationTargetException, IllegalAccessException, InstantiationException {
blackhole.consume(state.currentApplication.benchmark());
}
// public static void main(String[] args) throws RunnerException, IOException {
......
......@@ -67,10 +67,11 @@ public abstract class Application<T> {
return selected;
}
public void benchmark() throws InvocationTargetException, IllegalAccessException, InstantiationException {
public T benchmark() throws InvocationTargetException, IllegalAccessException, InstantiationException {
for(int i = 0; i < applicationSize; ++i) {
methodsToCall[i].invoke(this);
}
return dataStructure;
}
abstract public int generateIndex();
......
......@@ -65,10 +65,4 @@ public class CollectionApplication<T extends Collection> extends Application<T>
dataStructure.toArray(array);
}
}
@Override
public void benchmark() throws InvocationTargetException, IllegalAccessException, InstantiationException {
super.benchmark();
dataStructure = (T) dataStructure.getClass().newInstance();
}
}
......@@ -43,12 +43,6 @@ public class MapApplication extends Application<Map<Integer, Integer>> {
public void runValues() { dataStructure.values(); }
@Override
public void benchmark() throws InvocationTargetException, IllegalAccessException, InstantiationException {
super.benchmark();
dataStructure = dataStructure.getClass().newInstance();
}
@Override
public int generateIndex() {
return randomGenerator.nextInt(2 * dataStructure.size() + 1);
......
Markdown is supported
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