Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit 78e2b24

Browse files
committed
Added another baseline benchmark against StringUtils.split() from commons-lang
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1658392 13f79535-47bb-0310-9956-ffa450edef68
1 parent 64f454e commit 78e2b24

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,12 @@ CSV files of various types.
431431
<scope>system</scope>
432432
<systemPath>${basedir}/csv-1.0.jar</systemPath>
433433
</dependency>
434+
435+
<dependency>
436+
<groupId>org.apache.commons</groupId>
437+
<artifactId>commons-lang3</artifactId>
438+
<version>3.2.1</version>
439+
</dependency>
434440
</dependencies>
435441

436442
<properties>

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.concurrent.TimeUnit;
2525

2626
import com.generationjava.io.CsvReader;
27+
import org.apache.commons.lang3.StringUtils;
2728
import org.openjdk.jmh.annotations.Benchmark;
2829
import org.openjdk.jmh.annotations.BenchmarkMode;
2930
import org.openjdk.jmh.annotations.Fork;
@@ -39,8 +40,8 @@
3940
@BenchmarkMode(Mode.AverageTime)
4041
@Fork(value = 1, jvmArgs = "-server")
4142
@Threads(1)
42-
@Warmup(iterations = 10)
43-
@Measurement(iterations = 10)
43+
@Warmup(iterations = 5)
44+
@Measurement(iterations = 20)
4445
@OutputTimeUnit(TimeUnit.MILLISECONDS)
4546
public class CSVBenchmark {
4647

@@ -49,7 +50,7 @@ private BufferedReader getReader() throws IOException {
4950
}
5051

5152
@Benchmark
52-
public int baseline(Blackhole bh) throws Exception {
53+
public int read(Blackhole bh) throws Exception {
5354
BufferedReader in = getReader();
5455
int count = 0;
5556
String line;
@@ -62,6 +63,21 @@ public int baseline(Blackhole bh) throws Exception {
6263
return count;
6364
}
6465

66+
@Benchmark
67+
public int split(Blackhole bh) throws Exception {
68+
BufferedReader in = getReader();
69+
int count = 0;
70+
String line;
71+
while ((line = in.readLine()) != null) {
72+
String[] values = StringUtils.split(line, ',');
73+
count += values.length;
74+
}
75+
76+
bh.consume(count);
77+
in.close();
78+
return count;
79+
}
80+
6581
@Benchmark
6682
public int parseCommonsCSV(Blackhole bh) throws Exception {
6783
BufferedReader in = getReader();

0 commit comments

Comments
 (0)