Author: ebourg Date: Tue Feb 10 09:46:36 2015 New Revision: 1658653 URL: http://svn.apache.org/r1658653 Log: Load the data in memory before running the benchmarks
Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVBenchmark.java Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVBenchmark.java URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVBenchmark.java?rev=1658653&r1=1658652&r2=1658653&view=diff ============================================================================== --- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVBenchmark.java (original) +++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVBenchmark.java Tue Feb 10 09:46:36 2015 @@ -18,12 +18,17 @@ package org.apache.commons.csv; import java.io.BufferedReader; -import java.io.FileReader; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.StringReader; import java.util.List; import java.util.concurrent.TimeUnit; +import java.util.zip.GZIPInputStream; import com.generationjava.io.CsvReader; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; @@ -31,6 +36,9 @@ import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Threads; import org.openjdk.jmh.annotations.Warmup; import org.openjdk.jmh.infra.Blackhole; @@ -38,15 +46,29 @@ import org.supercsv.io.CsvListReader; import org.supercsv.prefs.CsvPreference; @BenchmarkMode(Mode.AverageTime) -@Fork(value = 1, jvmArgs = {"-server", "-Xms128M", "-Xmx128M"}) +@Fork(value = 1, jvmArgs = {"-server", "-Xms1024M", "-Xmx1024M"}) @Threads(1) @Warmup(iterations = 5) @Measurement(iterations = 20) @OutputTimeUnit(TimeUnit.MILLISECONDS) +@State(Scope.Benchmark) public class CSVBenchmark { + private String data; + + /** + * Load the data in memory before running the benchmarks, this takes out IO from the results. + */ + @Setup + public void init() throws IOException { + File file = new File("src/test/resources/perf/worldcitiespop.txt.gz"); + InputStream in = new GZIPInputStream(new FileInputStream(file)); + this.data = IOUtils.toString(in, "ISO-8859-1"); + in.close(); + } + private BufferedReader getReader() throws IOException { - return new BufferedReader(new FileReader("worldcitiespop.txt")); + return new BufferedReader(new StringReader(data)); } @Benchmark