Skip to content

Commit 304f191

Browse files
committed
Load the data in memory before running the benchmarks
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1658653 13f79535-47bb-0310-9956-ffa450edef68
1 parent fd10558 commit 304f191

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

src/test/java/org/apache/commons/csv/CSVBenchmark.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,57 @@
1818
package org.apache.commons.csv;
1919

2020
import java.io.BufferedReader;
21-
import java.io.FileReader;
21+
import java.io.File;
22+
import java.io.FileInputStream;
2223
import java.io.IOException;
24+
import java.io.InputStream;
25+
import java.io.StringReader;
2326
import java.util.List;
2427
import java.util.concurrent.TimeUnit;
28+
import java.util.zip.GZIPInputStream;
2529

2630
import com.generationjava.io.CsvReader;
31+
import org.apache.commons.io.IOUtils;
2732
import org.apache.commons.lang3.StringUtils;
2833
import org.openjdk.jmh.annotations.Benchmark;
2934
import org.openjdk.jmh.annotations.BenchmarkMode;
3035
import org.openjdk.jmh.annotations.Fork;
3136
import org.openjdk.jmh.annotations.Measurement;
3237
import org.openjdk.jmh.annotations.Mode;
3338
import org.openjdk.jmh.annotations.OutputTimeUnit;
39+
import org.openjdk.jmh.annotations.Scope;
40+
import org.openjdk.jmh.annotations.Setup;
41+
import org.openjdk.jmh.annotations.State;
3442
import org.openjdk.jmh.annotations.Threads;
3543
import org.openjdk.jmh.annotations.Warmup;
3644
import org.openjdk.jmh.infra.Blackhole;
3745
import org.supercsv.io.CsvListReader;
3846
import org.supercsv.prefs.CsvPreference;
3947

4048
@BenchmarkMode(Mode.AverageTime)
41-
@Fork(value = 1, jvmArgs = {"-server", "-Xms128M", "-Xmx128M"})
49+
@Fork(value = 1, jvmArgs = {"-server", "-Xms1024M", "-Xmx1024M"})
4250
@Threads(1)
4351
@Warmup(iterations = 5)
4452
@Measurement(iterations = 20)
4553
@OutputTimeUnit(TimeUnit.MILLISECONDS)
54+
@State(Scope.Benchmark)
4655
public class CSVBenchmark {
4756

57+
private String data;
58+
59+
/**
60+
* Load the data in memory before running the benchmarks, this takes out IO from the results.
61+
*/
62+
@Setup
63+
public void init() throws IOException {
64+
File file = new File("src/test/resources/perf/worldcitiespop.txt.gz");
65+
InputStream in = new GZIPInputStream(new FileInputStream(file));
66+
this.data = IOUtils.toString(in, "ISO-8859-1");
67+
in.close();
68+
}
69+
4870
private BufferedReader getReader() throws IOException {
49-
return new BufferedReader(new FileReader("worldcitiespop.txt"));
71+
return new BufferedReader(new StringReader(data));
5072
}
5173

5274
@Benchmark

0 commit comments

Comments
 (0)