| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
package org.perfidix.element; |
| 28 | |
|
| 29 | |
import java.util.ArrayList; |
| 30 | |
import java.util.Comparator; |
| 31 | |
import java.util.Hashtable; |
| 32 | |
import java.util.List; |
| 33 | |
import java.util.Map; |
| 34 | |
import java.util.Map.Entry; |
| 35 | |
import java.util.Set; |
| 36 | |
import java.util.TreeSet; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
public final class SequentialMethodArrangement extends AbstractMethodArrangement { |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
protected SequentialMethodArrangement(final List<BenchmarkElement> elements) { |
| 64 | 10 | super(elements); |
| 65 | 10 | } |
| 66 | |
|
| 67 | |
|
| 68 | |
@Override |
| 69 | |
protected List<BenchmarkElement> arrangeList(final List<BenchmarkElement> elements) { |
| 70 | 10 | final Map<BenchmarkMethod, ArrayList<BenchmarkElement>> table = |
| 71 | |
new Hashtable<BenchmarkMethod, ArrayList<BenchmarkElement>>(); |
| 72 | 10 | final List<BenchmarkElement> returnVal = new ArrayList<BenchmarkElement>(); |
| 73 | |
|
| 74 | |
|
| 75 | 10 | for (final BenchmarkElement elem : elements) { |
| 76 | 3080 | if (!table.containsKey(elem.getMeth())) { |
| 77 | 50 | table.put(elem.getMeth(), new ArrayList<BenchmarkElement>()); |
| 78 | |
} |
| 79 | 3080 | table.get(elem.getMeth()).add(elem); |
| 80 | 3080 | } |
| 81 | |
|
| 82 | |
|
| 83 | 10 | int numberOfElements = 0; |
| 84 | 10 | for (final BenchmarkMethod meth : table.keySet()) { |
| 85 | 50 | numberOfElements = numberOfElements + table.get(meth).size(); |
| 86 | 50 | } |
| 87 | |
|
| 88 | |
|
| 89 | 10 | final Set<Entry<BenchmarkMethod, ArrayList<BenchmarkElement>>> compareMethods = |
| 90 | |
new TreeSet<Entry<BenchmarkMethod, ArrayList<BenchmarkElement>>>(new BenchmarkElementComparator()); |
| 91 | 10 | for (final Entry<BenchmarkMethod, ArrayList<BenchmarkElement>> entry : table.entrySet()) { |
| 92 | 50 | compareMethods.add(entry); |
| 93 | 50 | } |
| 94 | |
|
| 95 | 10 | final ArrayList<BenchmarkMethod> methods = new ArrayList<BenchmarkMethod>(); |
| 96 | 10 | for (Entry<BenchmarkMethod, ArrayList<BenchmarkElement>> entry : compareMethods) { |
| 97 | 50 | methods.add(entry.getKey()); |
| 98 | 50 | } |
| 99 | |
|
| 100 | 3090 | for (int i = 0; i < numberOfElements; i++) { |
| 101 | 3080 | BenchmarkElement elem = null; |
| 102 | 3080 | int indexPart = 0; |
| 103 | 7525 | while (elem == null) { |
| 104 | 4445 | final int index = (i + indexPart) % methods.size(); |
| 105 | 4445 | final BenchmarkMethod methodToInclude = methods.get(index); |
| 106 | 4445 | if (table.containsKey(methodToInclude)) { |
| 107 | 3080 | elem = table.get(methodToInclude).remove(0); |
| 108 | 3080 | if (table.get(methodToInclude).size() == 0) { |
| 109 | 50 | table.remove(methodToInclude); |
| 110 | |
} |
| 111 | |
} |
| 112 | 4445 | indexPart++; |
| 113 | 4445 | } |
| 114 | 3080 | returnVal.add(elem); |
| 115 | |
} |
| 116 | 10 | return returnVal; |
| 117 | |
} |
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | 110 | class BenchmarkElementComparator implements |
| 126 | |
Comparator<Entry<BenchmarkMethod, ArrayList<BenchmarkElement>>> { |
| 127 | |
|
| 128 | |
|
| 129 | |
public int compare(final Entry<BenchmarkMethod, ArrayList<BenchmarkElement>> object1, |
| 130 | |
final Entry<BenchmarkMethod, ArrayList<BenchmarkElement>> object2) { |
| 131 | 100 | int returnVal = 0; |
| 132 | 100 | if (object1.getValue().size() > object2.getValue().size()) { |
| 133 | 45 | returnVal = -1; |
| 134 | |
} else { |
| 135 | 55 | returnVal = 1; |
| 136 | |
} |
| 137 | 100 | return returnVal; |
| 138 | |
} |
| 139 | |
|
| 140 | |
} |
| 141 | |
|
| 142 | |
} |