aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--JavaCSVTest.java29
-rw-r--r--README.txt3
-rwxr-xr-xbench.rb4
-rw-r--r--opencsv-2.3.jarbin0 -> 19526 bytes
-rw-r--r--rb-test.rb12
-rw-r--r--results.txt8
7 files changed, 51 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 72699f7..a9ab7de 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
/*.csv
+/*.class
+/cr-test
diff --git a/JavaCSVTest.java b/JavaCSVTest.java
new file mode 100644
index 0000000..91ee366
--- /dev/null
+++ b/JavaCSVTest.java
@@ -0,0 +1,29 @@
+import au.com.bytecode.opencsv.CSVReader;
+import au.com.bytecode.opencsv.CSVWriter;
+import java.io.FileReader;
+import java.io.FileWriter;
+
+public class JavaCSVTest {
+ private static String[] concat(final String a[], final String b[]) {
+ final String r[] = new String[a.length + b.length];
+
+ System.arraycopy(a, 0, r, 0, a.length);
+ System.arraycopy(b, 0, r, a.length, b.length);
+
+ return r;
+ }
+
+ private static final String FOO[] = { "foo", "foo" };
+
+ public static void main(String args[]) throws Exception {
+ final String src_path = args[0], dst_path = args[1];
+ final CSVReader src = new CSVReader(new FileReader(src_path));
+ final CSVWriter dst = new CSVWriter(new FileWriter(dst_path));
+
+ String row[];
+ while ((row = src.readNext()) != null)
+ dst.writeNext(concat(row, FOO));
+
+ dst.close();
+ }
+}
diff --git a/README.txt b/README.txt
index 1dd6cd9..a82d866 100644
--- a/README.txt
+++ b/README.txt
@@ -5,5 +5,8 @@ Setup:
# compile crystal test
crystal build --release cr-test.cr
+ # compile java test
+ javac -cp opencsv-2.3.jar JavaCSVTest.java
+
# compare tests
./bench.rb
diff --git a/bench.rb b/bench.rb
index 83f4113..ea983b3 100755
--- a/bench.rb
+++ b/bench.rb
@@ -7,6 +7,10 @@ Benchmark.bm(5) do |bm|
`python2.7 ./py-test.py test.csv out.csv`
end
+ bm.report('java') do
+ `java -cp opencsv-2.3.jar:. JavaCSVTest test.csv out.csv`
+ end
+
bm.report('ruby') do
`ruby ./rb-test.rb test.csv out.csv`
end
diff --git a/opencsv-2.3.jar b/opencsv-2.3.jar
new file mode 100644
index 0000000..31fcf30
--- /dev/null
+++ b/opencsv-2.3.jar
Binary files differ
diff --git a/rb-test.rb b/rb-test.rb
index 973c8cf..4bd2e57 100644
--- a/rb-test.rb
+++ b/rb-test.rb
@@ -5,8 +5,14 @@ require 'csv'
# get paths
src_path, dst_path = ARGV
-CSV.open(dst_path, 'wb') do |dst|
- CSV.foreach(src_path) do |row|
- dst << (row += %w{foo} * 2)
+File.open(dst_path, 'wb') do |dst_file|
+ CSV(dst_file) do |dst|
+ File.open(src_path, 'rb') do |src_file|
+ CSV(src_file) do |src|
+ src.each do |row|
+ dst << row + (%w{foo} * 2)
+ end
+ end
+ end
end
end
diff --git a/results.txt b/results.txt
index 4b530e6..9d1efd3 100644
--- a/results.txt
+++ b/results.txt
@@ -1,5 +1,5 @@
-pabs@meh:~/git/csv-test> ./bench.rb
user system total real
-python 0.000000 0.000000 15.620000 ( 15.862860)
-ruby 0.000000 0.000000 139.730000 (140.269987)
-crystal 0.000000 0.000000 13.300000 ( 13.153701)
+python 0.000000 0.000000 15.170000 ( 15.388455)
+java 0.000000 0.000000 7.680000 ( 7.818470)
+ruby 0.000000 0.000000 132.520000 (133.027950)
+crystal 0.000000 0.000000 13.530000 ( 13.249648)