Last active
September 20, 2016 10:33
-
-
Save VladVin/5bc92839c110894588fc90247643f30a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package becnhmark; | |
import com.google.caliper.BeforeExperiment; | |
import com.google.caliper.Param; | |
import sort_algs.Sorter; | |
import java.io.*; | |
import java.util.ArrayList; | |
public class Benchmark { | |
@Param | |
private String pathToData; | |
private double[] array; | |
private double[] arrayCopy; | |
private Sorter sorter; | |
@BeforeExperiment | |
public void setUp() throws IOException { | |
sorter = new Sorter(); | |
loadData(); | |
arrayCopy = new double[array.length]; | |
} | |
@com.google.caliper.Benchmark | |
public void timeSortArray(int reps) { | |
for (int i = 0; i < reps; i++) { | |
System.arraycopy(array, 0, arrayCopy, 0, array.length); | |
sorter.sort(arrayCopy); | |
} | |
} | |
private void loadData() throws IOException { | |
BufferedReader br = new BufferedReader(new FileReader(pathToData)); | |
ArrayList<Double> doubles = new ArrayList<Double>(); | |
String line; | |
while ((line = br.readLine()) != null) { | |
double number; | |
try { | |
number = Double.parseDouble(line); | |
} catch (NumberFormatException ex){ | |
continue; | |
} | |
doubles.add(number); | |
} | |
br.close(); | |
array = new double[doubles.size()]; | |
for (int i = 0; i < array.length; i++) { | |
array[i] = doubles.get(i); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example; | |
import becnhmark.Benchmark; | |
import com.google.caliper.runner.CaliperMain; | |
public class StartBenchmark { | |
public static void main(String[] args) { | |
CaliperMain.main(Benchmark.class, args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Command line arguments:
-DpathToData="<path_to_txt1>[, path_to_txt2, ...]"