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

Commit ef959bef authored by Noric Couderc's avatar Noric Couderc

Implemented population of data structures before benchmarking.

I wanted to initialize data structures with different sizes before running the
benchmark, so I implemented a method populate() that initialises a data
structure of the right size filled with random values.
parent 95e813a3
......@@ -23,6 +23,9 @@ public class ListApplicationBenchmark {
@Param({"LinkedList", "ArrayList", "Vector"})
public String datastructureName;
@Param({"0", "1000", "2000"})
public int baseStructureSize;
public Application currentApplication;
@Setup(Level.Trial)
......@@ -35,6 +38,7 @@ public class ListApplicationBenchmark {
default: datastructure = new ArrayList<>(); break;
}
currentApplication = new ListApplication(seed, applicationSize, datastructure);
currentApplication.populate(baseStructureSize);
}
}
......
......@@ -19,12 +19,16 @@ public class MapApplicationBenchmark {
@Param({"HashMap", "TreeMap", "IdentityHashMap", "LinkedHashMap", "WeakHashMap"})
public String datastructureName;
@Param({"0", "1000", "2000"})
public int baseStructureSize;
public Application currentApplication;
@Setup(Level.Trial)
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);
}
}
......
......@@ -19,12 +19,16 @@ public class SetApplicationBenchmark {
@Param({"HashSet", "TreeSet", "LinkedHashSet"})
public String datastructureName;
@Param({"0", "1000", "2000"})
public int baseStructureSize;
public Application currentApplication;
@Setup(Level.Trial)
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);
}
}
......
......@@ -74,6 +74,8 @@ public abstract class Application<T> {
return dataStructure;
}
abstract public void populate(int numberElements);
abstract public int generateIndex();
public T getDataStructure() { return dataStructure; }
......
......@@ -12,6 +12,11 @@ public class CollectionApplication<T extends Collection> extends Application<T>
randomGenerator.ints(100).forEach((i) -> argument.add(i));
}
@Override
public void populate(int numberElements) {
randomGenerator.ints(numberElements).forEach((i) -> dataStructure.add(i));
}
public int generateIndex() {
return randomGenerator.nextInt(dataStructure.size());
}
......
......@@ -9,6 +9,15 @@ public class MapApplication extends Application<Map<Integer, Integer>> {
super(seed, applicationSize, structure);
}
@Override
public void populate(int numberElements) {
for (int i = 0; i < numberElements; ++i) {
int k = generateIndex();
int v = randomGenerator.nextInt();
dataStructure.put(k, v);
}
}
public void runClear() { dataStructure.clear(); }
public void runContainsKey() { dataStructure.containsKey(generateIndex()); }
......
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