1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.supercsv.benchmark;
17  
18  import java.io.FileReader;
19  
20  import org.junit.FixMethodOrder;
21  import org.junit.Test;
22  import org.junit.runners.MethodSorters;
23  import org.supercsv.benchmark.cellprocessor.ParseIconColour;
24  import org.supercsv.benchmark.cellprocessor.ParseStopType;
25  import org.supercsv.benchmark.cellprocessor.ParseStopTypeAndName;
26  import org.supercsv.benchmark.model.TransportLocation;
27  import org.supercsv.benchmark.model.TransportLocationStrings;
28  import org.supercsv.cellprocessor.Optional;
29  import org.supercsv.cellprocessor.ParseDouble;
30  import org.supercsv.cellprocessor.constraint.NotNull;
31  import org.supercsv.cellprocessor.ift.CellProcessor;
32  import org.supercsv.prefs.CsvPreference;
33  
34  import com.carrotsearch.junitbenchmarks.annotation.BenchmarkMethodChart;
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  @BenchmarkMethodChart(filePrefix = "StandardCsvReadingBenchmark")
47  @FixMethodOrder(MethodSorters.NAME_ASCENDING)
48  public class StandardCsvReadingBenchmarkTest extends AbstractCsvReadingBenchmark {
49  
50  	private static final CsvPreference PREFS = new CsvPreference.Builder(
51  			CsvPreference.STANDARD_PREFERENCE).build();
52  
53  	
54  	private static final String CSV_FILE = "Britain's transport infrastructure.csv";
55  
56  	public static final CellProcessor[] PROCESSORS = { new NotNull(), 
57  			new NotNull(new ParseDouble()), 
58  			new NotNull(new ParseDouble()), 
59  			new NotNull(new ParseDouble()), 
60  			new NotNull(new ParseDouble()), 
61  			new NotNull(), 
62  			new Optional(), 
63  			new NotNull(), 
64  			new NotNull(), 
65  			new Optional(), 
66  			new NotNull(), 
67  			new Optional(), 
68  			new NotNull(new ParseStopType()), 
69  			new NotNull(new ParseStopTypeAndName()), 
70  			new NotNull(new ParseIconColour()), 
71  	};
72  
73  	
74  	private static final int ROWS = 50000;
75  
76  	
77  
78  
79  	@Test
80  	public void testCsvListReader() throws Exception {
81  		timeCsvListReader(new FileReader(CSV_FILE), PREFS, ROWS);
82  	}
83  
84  	
85  
86  
87  	@Test
88  	public void testCsvListReaderUsingProcessors() throws Exception {
89  		timeCsvListReaderUsingProcessors(new FileReader(CSV_FILE), PREFS,
90  				PROCESSORS, ROWS);
91  	}
92  
93  	
94  
95  
96  	@Test
97  	public void testCsvMapReader() throws Exception {
98  		timeCsvMapReader(new FileReader(CSV_FILE), PREFS, ROWS);
99  	}
100 
101 	
102 
103 
104 	@Test
105 	public void testCsvMapReaderUsingProcessors() throws Exception {
106 		timeCsvMapReaderUsingProcessors(new FileReader(CSV_FILE), PREFS,
107 				PROCESSORS, ROWS);
108 	}
109 
110 	
111 
112 
113 	@Test
114 	public void testCsvBeanReader() throws Exception {
115 		timeCsvBeanReader(new FileReader(CSV_FILE), PREFS,
116 				TransportLocationStrings.class, ROWS);
117 	}
118 
119 	
120 
121 
122 	@Test
123 	public void testCsvBeanReaderUsingProcessors() throws Exception {
124 		timeCsvBeanReaderUsingProcessors(new FileReader(CSV_FILE), PREFS,
125 				TransportLocation.class, PROCESSORS, ROWS);
126 	}
127 
128 	
129 
130 
131 	@Test
132 	public void testCsvDozerBeanReader() throws Exception {
133 		timeCsvDozerBeanReader(new FileReader(CSV_FILE), PREFS,
134 				TransportLocationStrings.class, ROWS);
135 	}
136 
137 	
138 
139 
140 	@Test
141 	public void testCsvDozerBeanReaderUsingProcessors() throws Exception {
142 		timeCsvDozerBeanReaderUsingProcessors(new FileReader(CSV_FILE), PREFS,
143 				TransportLocation.class, PROCESSORS, ROWS);
144 	}
145 
146 }