forked from Hithomelabs/Princeton1
Reviewed-on: Hithomelabs/Princeton1#17 Reviewed-by: kruti <krutis0201@gmail.com> Co-authored-by: hitanshu310 <hitanshu98@gmail.com> Co-committed-by: hitanshu310 <hitanshu98@gmail.com>
48 lines
1.5 KiB
Java
48 lines
1.5 KiB
Java
package com.hithomelabs.clients.Benchmarks;
|
|
|
|
import com.hithomelabs.clients.Benchmarks.Sortables.*;
|
|
import com.hithomelabs.princeton1.common.Apple;
|
|
import com.hithomelabs.princeton1.module5.MeasurableSort;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class BenchMark {
|
|
|
|
private ArraySize size;
|
|
private List<MeasurableSort<Apple>> algorithms;
|
|
private List<Sortable<Apple>> sortableCollections;
|
|
private static final String header = "| ARRAY NATURE | ALGORITHM | TIME ELAPSED (ns) | COMPARES | EXCHANGES |";
|
|
// * Helps get a table in markdown
|
|
private static final String markdownTableFormatter = "|--|--|--|--|--|";
|
|
|
|
|
|
BenchMark(int size, List<MeasurableSort<Apple>> algorithms) {
|
|
this.size = new ArraySize(size);
|
|
this.algorithms = algorithms;
|
|
sortableCollections = new ArrayList<Sortable<Apple>>();
|
|
sortableCollections.add(new AlreadySortedApples(size));
|
|
sortableCollections.add(new PartiallySortedApples(size, 1000));
|
|
sortableCollections.add(new ReverseSortedApples(size));
|
|
sortableCollections.add(new RandomlySizedApples(size, 1000));
|
|
sortableCollections.add(new FewFrequentlyOccuringApples(size));
|
|
}
|
|
|
|
public void run() {
|
|
|
|
System.out.println(size);
|
|
System.out.println(header);
|
|
System.out.println(markdownTableFormatter);
|
|
for(Sortable<Apple> array: sortableCollections){
|
|
new Bundle<Apple>(array, algorithms).run(Apple.COMPARE_BY_SIZE);
|
|
}
|
|
System.out.println();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|