|
18 | 18 | package org.apache.commons.csv; |
19 | 19 |
|
20 | 20 | import java.io.BufferedReader; |
21 | | -import java.io.FileReader; |
| 21 | +import java.io.File; |
| 22 | +import java.io.FileInputStream; |
22 | 23 | import java.io.IOException; |
| 24 | +import java.io.InputStream; |
| 25 | +import java.io.StringReader; |
23 | 26 | import java.util.List; |
24 | 27 | import java.util.concurrent.TimeUnit; |
| 28 | +import java.util.zip.GZIPInputStream; |
25 | 29 |
|
26 | 30 | import com.generationjava.io.CsvReader; |
| 31 | +import org.apache.commons.io.IOUtils; |
27 | 32 | import org.apache.commons.lang3.StringUtils; |
28 | 33 | import org.openjdk.jmh.annotations.Benchmark; |
29 | 34 | import org.openjdk.jmh.annotations.BenchmarkMode; |
30 | 35 | import org.openjdk.jmh.annotations.Fork; |
31 | 36 | import org.openjdk.jmh.annotations.Measurement; |
32 | 37 | import org.openjdk.jmh.annotations.Mode; |
33 | 38 | 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; |
34 | 42 | import org.openjdk.jmh.annotations.Threads; |
35 | 43 | import org.openjdk.jmh.annotations.Warmup; |
36 | 44 | import org.openjdk.jmh.infra.Blackhole; |
37 | 45 | import org.supercsv.io.CsvListReader; |
38 | 46 | import org.supercsv.prefs.CsvPreference; |
39 | 47 |
|
40 | 48 | @BenchmarkMode(Mode.AverageTime) |
41 | | -@Fork(value = 1, jvmArgs = {"-server", "-Xms128M", "-Xmx128M"}) |
| 49 | +@Fork(value = 1, jvmArgs = {"-server", "-Xms1024M", "-Xmx1024M"}) |
42 | 50 | @Threads(1) |
43 | 51 | @Warmup(iterations = 5) |
44 | 52 | @Measurement(iterations = 20) |
45 | 53 | @OutputTimeUnit(TimeUnit.MILLISECONDS) |
| 54 | +@State(Scope.Benchmark) |
46 | 55 | public class CSVBenchmark { |
47 | 56 |
|
| 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 | + |
48 | 70 | private BufferedReader getReader() throws IOException { |
49 | | - return new BufferedReader(new FileReader("worldcitiespop.txt")); |
| 71 | + return new BufferedReader(new StringReader(data)); |
50 | 72 | } |
51 | 73 |
|
52 | 74 | @Benchmark |
|
0 commit comments