Commit 442d5113 authored by Noric Couderc's avatar Noric Couderc
Browse files

Rename "Application" to "Synthetic Benchmark"

Synthetic benchmark is a better name. Required quite some refactoring.
parent 4e516952
......@@ -2,8 +2,8 @@ package se.lth.cs.jmh;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import se.lth.cs.Application;
import se.lth.cs.ListApplication;
import se.lth.cs.SyntheticBenchmark;
import se.lth.cs.ListSyntheticBenchmark;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
......@@ -28,7 +28,7 @@ public class ListApplicationBenchmark {
@Param({"0", "1000", "10000", "1000000"})
public int baseStructureSize;
public Application currentApplication;
public SyntheticBenchmark currentSyntheticBenchmark;
@Setup(Level.Invocation)
public void doSetup() {
......@@ -39,17 +39,17 @@ public class ListApplicationBenchmark {
case "Vector": datastructure = new Vector<>(); break;
default: datastructure = new ArrayList<>(); break;
}
currentApplication = new ListApplication(seed, applicationSize, datastructure);
currentApplication.populate(baseStructureSize);
currentSyntheticBenchmark = new ListSyntheticBenchmark(seed, applicationSize, datastructure);
currentSyntheticBenchmark.populate(baseStructureSize);
}
}
@Benchmark
public void ListApplicationBenchmark(ListBenchmarkState state, Blackhole blackhole) throws InvocationTargetException, IllegalAccessException, InstantiationException {
while (state.currentApplication.hasNext()) {
blackhole.consume(state.currentApplication.invokeCurrentMethod());
state.currentApplication.tick();
while (state.currentSyntheticBenchmark.hasNext()) {
blackhole.consume(state.currentSyntheticBenchmark.invokeCurrentMethod());
state.currentSyntheticBenchmark.tick();
}
blackhole.consume(state.currentApplication.getDataStructure());
blackhole.consume(state.currentSyntheticBenchmark.getDataStructure());
}
}
......@@ -2,8 +2,8 @@ package se.lth.cs.jmh;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import se.lth.cs.Application;
import se.lth.cs.MapApplication;
import se.lth.cs.SyntheticBenchmark;
import se.lth.cs.MapSyntheticBenchmark;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
......@@ -24,22 +24,22 @@ public class MapApplicationBenchmark {
@Param({"0", "1000", "10000", "1000000"})
public int baseStructureSize;
public Application currentApplication;
public SyntheticBenchmark currentSyntheticBenchmark;
@Setup(Level.Invocation)
public void doSetup() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
Map<Integer, Integer> datastructure = (Map<Integer, Integer>) Class.forName("java.util." + datastructureName).newInstance();
currentApplication = new MapApplication(seed, applicationSize, datastructure);
currentApplication.populate(baseStructureSize);
currentSyntheticBenchmark = new MapSyntheticBenchmark(seed, applicationSize, datastructure);
currentSyntheticBenchmark.populate(baseStructureSize);
}
}
@Benchmark
public void MapApplicationBenchmark(MapBenchmarkState state, Blackhole blackhole) throws InvocationTargetException, IllegalAccessException, InstantiationException {
while (state.currentApplication.hasNext()) {
blackhole.consume(state.currentApplication.invokeCurrentMethod());
state.currentApplication.tick();
while (state.currentSyntheticBenchmark.hasNext()) {
blackhole.consume(state.currentSyntheticBenchmark.invokeCurrentMethod());
state.currentSyntheticBenchmark.tick();
}
blackhole.consume(state.currentApplication.getDataStructure());
blackhole.consume(state.currentSyntheticBenchmark.getDataStructure());
}
}
......@@ -2,8 +2,8 @@ package se.lth.cs.jmh;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import se.lth.cs.Application;
import se.lth.cs.SetApplication;
import se.lth.cs.SyntheticBenchmark;
import se.lth.cs.SetSyntheticBenchmark;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
......@@ -24,22 +24,22 @@ public class SetApplicationBenchmark {
@Param({"0", "1000", "10000", "1000000"})
public int baseStructureSize;
public Application currentApplication;
public SyntheticBenchmark currentSyntheticBenchmark;
@Setup(Level.Invocation)
public void doSetup() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
Set<Integer> datastructure = (Set<Integer>) Class.forName("java.util." + datastructureName).newInstance();
currentApplication = new SetApplication(seed, applicationSize, datastructure);
currentApplication.populate(baseStructureSize);
currentSyntheticBenchmark = new SetSyntheticBenchmark(seed, applicationSize, datastructure);
currentSyntheticBenchmark.populate(baseStructureSize);
}
}
@Benchmark
public void SetApplicationBenchmark(SetBenchmarkState state, Blackhole blackhole) throws InvocationTargetException, IllegalAccessException, InstantiationException {
while (state.currentApplication.hasNext()) {
blackhole.consume(state.currentApplication.invokeCurrentMethod());
state.currentApplication.tick();
while (state.currentSyntheticBenchmark.hasNext()) {
blackhole.consume(state.currentSyntheticBenchmark.invokeCurrentMethod());
state.currentSyntheticBenchmark.tick();
}
blackhole.consume(state.currentApplication.getDataStructure());
blackhole.consume(state.currentSyntheticBenchmark.getDataStructure());
}
}
package se.lth.cs.ApplicationGeneration;
import se.lth.cs.Application;
import se.lth.cs.ListApplication;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
public class ListApplicationGenerator implements ApplicationGenerator {
@Override
public List<Application<?>> createApplications(int seed, int number, int size) {
List<Application<?>> listApplications = new ArrayList<>();
for (int i = 0; i < number; ++i) {
listApplications.add(new ListApplication(seed + i, size, new ArrayList<>()));
listApplications.add(new ListApplication(seed + i, size, new LinkedList<>()));
listApplications.add(new ListApplication(seed + i, size, new Vector<>()));
}
return listApplications;
}
}
package se.lth.cs.ApplicationGeneration;
import se.lth.cs.Application;
import se.lth.cs.MapApplication;
import java.util.*;
public class MapApplicationGenerator implements ApplicationGenerator {
@Override
public List<Application<?>> createApplications(int seed, int number, int size) {
List<Application<?>> mapApplications = new ArrayList<>();
for (int i = 0; i < number; ++i) {
mapApplications.add(new MapApplication(seed + i, size, new HashMap<>()));
mapApplications.add(new MapApplication(seed + i, size, new TreeMap<>()));
mapApplications.add(new MapApplication(seed + i, size, new IdentityHashMap<>()));
mapApplications.add(new MapApplication(seed + i, size, new LinkedHashMap<>()));
mapApplications.add(new MapApplication(seed + i, size, new WeakHashMap<>()));
}
return mapApplications;
}
}
package se.lth.cs.ApplicationGeneration;
import se.lth.cs.Application;
import se.lth.cs.SetApplication;
import java.util.*;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArraySet;
public class SetApplicationGenerator implements ApplicationGenerator {
@Override
public List<Application<?>> createApplications(int seed, int number, int size) {
List<Application<?>> setApplications = new ArrayList<>();
for (int i = 0; i < number; ++i) {
setApplications.add(new SetApplication(seed + i, size, new HashSet<>()));
setApplications.add(new SetApplication(seed + i, size, new TreeSet<>()));
setApplications.add(new SetApplication(seed + i, size, new LinkedHashSet<>()));
setApplications.add(new SetApplication(seed + i, size, new ConcurrentSkipListSet<>()));
setApplications.add(new SetApplication(seed + i, size, new CopyOnWriteArraySet<>()));
}
return setApplications;
}
}
......@@ -5,24 +5,24 @@ import java.util.Iterator;
import java.util.List;
import java.util.Random;
public class CollectionApplication<T extends Collection> extends Application<T> {
public class CollectionSyntheticBenchmark<T extends Collection> extends SyntheticBenchmark<T> {
CollectionApplication(int seed, int applicationSize, Collection structure) {
CollectionSyntheticBenchmark(int seed, int applicationSize, Collection structure) {
super(seed, applicationSize, (T) structure);
// We add random numbers to the argument for addAll(Collection)
randomGenerator.ints(100).forEach((i) -> argument.add(i));
}
public CollectionApplication(int seed, int applicationSize, int baseStructureSize, Collection<Integer> init) {
public CollectionSyntheticBenchmark(int seed, int applicationSize, int baseStructureSize, Collection<Integer> init) {
super(seed, applicationSize, baseStructureSize, (T) init);
}
public CollectionApplication(List<String> trace, Collection<Integer> init) {
public CollectionSyntheticBenchmark(List<String> trace, Collection<Integer> init) {
super(trace, (T) init);
}
public CollectionApplication(int seed, List<String> trace, Collection<Integer> init) {
public CollectionSyntheticBenchmark(int seed, List<String> trace, Collection<Integer> init) {
super(seed, trace, (T) init);
// We add random numbers to the argument for addAll(Collection)
......
package se.lth.cs;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
public class ListApplication extends CollectionApplication<List<Integer>> {
public class ListSyntheticBenchmark extends CollectionSyntheticBenchmark<List<Integer>> {
public ListApplication(int seed,
int applicationSize,
List<Integer> init) {
public ListSyntheticBenchmark(int seed,
int applicationSize,
List<Integer> init) {
super(seed, applicationSize, init);
}
public ListApplication(int seed,
int applicationSize,
int baseStructureSize,
List<Integer> init) {
public ListSyntheticBenchmark(int seed,
int applicationSize,
int baseStructureSize,
List<Integer> init) {
super(seed, applicationSize, baseStructureSize, init);
}
public ListApplication(List<String> trace, List<Integer> init) {
public ListSyntheticBenchmark(List<String> trace, List<Integer> init) {
super(trace, init);
}
......@@ -29,7 +28,7 @@ public class ListApplication extends CollectionApplication<List<Integer>> {
* @param trace
* @param init
*/
public ListApplication(int seed, List<String> trace, List<Integer> init) {
public ListSyntheticBenchmark(int seed, List<String> trace, List<Integer> init) {
super(seed, trace, init);
}
......
......@@ -2,21 +2,21 @@ package se.lth.cs;
import java.util.*;
public class MapApplication extends Application<Map<Integer, Integer>> {
public class MapSyntheticBenchmark extends SyntheticBenchmark<Map<Integer, Integer>> {
public MapApplication(int seed, int applicationSize, Map<Integer, Integer> structure) {
public MapSyntheticBenchmark(int seed, int applicationSize, Map<Integer, Integer> structure) {
super(seed, applicationSize, structure);
}
public MapApplication(int seed, int applicationSize, int baseStructureSize, Map<Integer, Integer> structure) {
public MapSyntheticBenchmark(int seed, int applicationSize, int baseStructureSize, Map<Integer, Integer> structure) {
super(seed, applicationSize, baseStructureSize, structure);
}
public MapApplication(List<String> trace, Map<Integer, Integer> init) {
public MapSyntheticBenchmark(List<String> trace, Map<Integer, Integer> init) {
super(trace, init);
}
public MapApplication(int seed, List<String> trace, Map<Integer, Integer> init) {
public MapSyntheticBenchmark(int seed, List<String> trace, Map<Integer, Integer> init) {
super(seed, trace, init);
}
......
......@@ -3,21 +3,21 @@ package se.lth.cs;
import java.util.List;
import java.util.Set;
public class SetApplication extends CollectionApplication<Set<Integer>> {
public class SetSyntheticBenchmark extends CollectionSyntheticBenchmark<Set<Integer>> {
public SetApplication(int seed, int applicationSize, Set<Integer> set) {
public SetSyntheticBenchmark(int seed, int applicationSize, Set<Integer> set) {
super(seed, applicationSize, set);
}
public SetApplication(int seed, int applicationSize, int baseStructureSize, Set<Integer> set) {
public SetSyntheticBenchmark(int seed, int applicationSize, int baseStructureSize, Set<Integer> set) {
super(seed, applicationSize, baseStructureSize, set);
}
public SetApplication(List<String> trace, Set<Integer> init) {
public SetSyntheticBenchmark(List<String> trace, Set<Integer> init) {
super(trace, init);
}
public SetApplication(int seed, List<String> trace, Set<Integer> init) {
public SetSyntheticBenchmark(int seed, List<String> trace, Set<Integer> init) {
super(seed, trace, init);
}
}
package se.lth.cs;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
......@@ -13,7 +10,7 @@ import java.util.stream.Stream;
/**
* An application, meaning "a generated application"
*/
public abstract class Application<T> {
public abstract class SyntheticBenchmark<T> {
Random randomGenerator;
......@@ -26,24 +23,24 @@ public abstract class Application<T> {
int seed;
int applicationSize;
int benchmarkSize;
int baseStructureSize;
Application(int seed, int applicationSize, T structure) {
SyntheticBenchmark(int seed, int benchmarkSize, T structure) {
this.seed = seed;
this.randomGenerator = new Random(seed);
this.applicationSize = applicationSize;
this.benchmarkSize = benchmarkSize;
initialize(structure);
List<Method> callableMethods = getRunnableMethods();
if (callableMethods.isEmpty()) { return; }
methodsToCall = getRandomTrace(applicationSize, callableMethods);
methodsToCall = getRandomTrace(benchmarkSize, callableMethods);
}
Application(List<String> trace, T structure) {
SyntheticBenchmark(List<String> trace, T structure) {
randomGenerator = new Random();
methodsToCall = new Method[trace.size()];
List<Method> callableMethods = getRunnableMethods();
......@@ -86,7 +83,7 @@ public abstract class Application<T> {
}
}
Application(int seed, List<String> trace, T structure) {
SyntheticBenchmark(int seed, List<String> trace, T structure) {
this(trace, structure);
this.seed = seed;
this.randomGenerator.setSeed(seed);
......@@ -109,6 +106,14 @@ public abstract class Application<T> {
return methodsToCall;
}
/**
* The public version of the method above, returns the list of methods that will be called in application
* @return a list of the methods that will be run
*/
public List<Method> getTrace() {
return Arrays.asList(methodsToCall);
}
/**
* Gets the list of runnable methods for the application
* (the methods whose name starts with "run")
......@@ -133,8 +138,8 @@ public abstract class Application<T> {
return allCallableMethods;
}
Application(int seed, int applicationSize, int baseStructureSize, T structure) {
this(seed, applicationSize, structure);
SyntheticBenchmark(int seed, int benchmarkSize, int baseStructureSize, T structure) {
this(seed, benchmarkSize, structure);
populate(baseStructureSize);
}
......
package se.lth.cs.SyntheticBenchmarkGeneration;
import se.lth.cs.SyntheticBenchmark;
import se.lth.cs.ListSyntheticBenchmark;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
public class ListSyntheticBenchmarkGenerator implements SyntheticBenchmarkGenerator {
@Override
public List<SyntheticBenchmark<?>> createApplications(int seed, int number, int size) {
List<SyntheticBenchmark<?>> listSyntheticBenchmarks = new ArrayList<>();
for (int i = 0; i < number; ++i) {
listSyntheticBenchmarks.add(new ListSyntheticBenchmark(seed + i, size, new ArrayList<>()));
listSyntheticBenchmarks.add(new ListSyntheticBenchmark(seed + i, size, new LinkedList<>()));
listSyntheticBenchmarks.add(new ListSyntheticBenchmark(seed + i, size, new Vector<>()));
}
return listSyntheticBenchmarks;
}
}
package se.lth.cs.SyntheticBenchmarkGeneration;
import se.lth.cs.MapSyntheticBenchmark;
import se.lth.cs.SyntheticBenchmark;
import java.util.*;
public class MapSyntheticBenchmarkGenerator implements SyntheticBenchmarkGenerator {
@Override
public List<SyntheticBenchmark<?>> createApplications(int seed, int number, int size) {
List<SyntheticBenchmark<?>> mapSyntheticBenchmarks = new ArrayList<>();
for (int i = 0; i < number; ++i) {
mapSyntheticBenchmarks.add(new MapSyntheticBenchmark(seed + i, size, new HashMap<>()));
mapSyntheticBenchmarks.add(new MapSyntheticBenchmark(seed + i, size, new TreeMap<>()));
mapSyntheticBenchmarks.add(new MapSyntheticBenchmark(seed + i, size, new IdentityHashMap<>()));
mapSyntheticBenchmarks.add(new MapSyntheticBenchmark(seed + i, size, new LinkedHashMap<>()));
mapSyntheticBenchmarks.add(new MapSyntheticBenchmark(seed + i, size, new WeakHashMap<>()));
}
return mapSyntheticBenchmarks;
}
}
package se.lth.cs.ApplicationGeneration;
package se.lth.cs.SyntheticBenchmarkGeneration;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* A class for converting method names for Lists, Maps, Sets, to
......
package se.lth.cs.SyntheticBenchmarkGeneration;
import se.lth.cs.SyntheticBenchmark;
import se.lth.cs.SetSyntheticBenchmark;
import java.util.*;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArraySet;
public class SetSyntheticBenchmarkGenerator implements SyntheticBenchmarkGenerator {
@Override
public List<SyntheticBenchmark<?>> createApplications(int seed, int number, int size) {
List<SyntheticBenchmark<?>> setSyntheticBenchmarks = new ArrayList<>();
for (int i = 0; i < number; ++i) {
setSyntheticBenchmarks.add(new SetSyntheticBenchmark(seed + i, size, new HashSet<>()));
setSyntheticBenchmarks.add(new SetSyntheticBenchmark(seed + i, size, new TreeSet<>()));
setSyntheticBenchmarks.add(new SetSyntheticBenchmark(seed + i, size, new LinkedHashSet<>()));
setSyntheticBenchmarks.add(new SetSyntheticBenchmark(seed + i, size, new ConcurrentSkipListSet<>()));
setSyntheticBenchmarks.add(new SetSyntheticBenchmark(seed + i, size, new CopyOnWriteArraySet<>()));
}
return setSyntheticBenchmarks;
}
}
package se.lth.cs.ApplicationGeneration;
package se.lth.cs.SyntheticBenchmarkGeneration;
import se.lth.cs.Application;
import se.lth.cs.SyntheticBenchmark;
import java.util.List;
public interface ApplicationGenerator {
public interface SyntheticBenchmarkGenerator {
/**
* Creates a list of list applications
......@@ -13,5 +13,5 @@ public interface ApplicationGenerator {
* @param size
* @return
*/
List<Application<?>> createApplications(int seed, int number, int size);
List<SyntheticBenchmark<?>> createApplications(int seed, int number, int size);
}
package se.lth.cs;
import java.util.List;
import java.util.stream.Collectors;
public class AppRunData {
public class SyntheticBenchmarkRunData {
private List<Double> samples;
protected Application<?> application;
protected SyntheticBenchmark<?> syntheticBenchmark;
public AppRunData(Application<?> application, List<Double> samples) {
this.application = application;
public SyntheticBenchmarkRunData(SyntheticBenchmark<?> syntheticBenchmark, List<Double> samples) {
this.syntheticBenchmark = syntheticBenchmark;
this.samples = samples;
}
......@@ -24,8 +23,8 @@ public class AppRunData {
return UtilsKt.variance(samples);
}
public Application<?> getApplication() {
return application;
public SyntheticBenchmark<?> getSyntheticBenchmark() {
return syntheticBenchmark;
}
public Double getMedian() {
......
package se.lth.cs;
import com.google.gson.Gson;
import se.lth.cs.ApplicationGeneration.ApplicationGenerator;
import se.lth.cs.ApplicationGeneration.ListApplicationGenerator;
import se.lth.cs.ApplicationGeneration.MapApplicationGenerator;
import se.lth.cs.ApplicationGeneration.SetApplicationGenerator;
import se.lth.cs.SyntheticBenchmarkGeneration.SyntheticBenchmarkGenerator;
import se.lth.cs.SyntheticBenchmarkGeneration.MapSyntheticBenchmarkGenerator;
import java.io.BufferedWriter;
import java.io.FileWriter;
......@@ -13,7 +11,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.stream.Collectors;
public class ApplicationRunner {
public class SyntheticBenchmarkRunner {
/**