diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-08-31 19:05:56 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-08-31 19:05:56 -0400 |
commit | 5339b9050a1e2bae6b8013f72e1a4e43f940290c (patch) | |
tree | c7c4a2ed52d22fc8bc36c06b17b3c5d8a5675621 | |
parent | f4e9ec22683fe87a50bab8457f0ea6ae6f91e76d (diff) | |
download | csv-test-master.tar.bz2 csv-test-master.zip |
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | JavaCSVTest.java | 29 | ||||
-rw-r--r-- | README.txt | 3 | ||||
-rwxr-xr-x | bench.rb | 4 | ||||
-rw-r--r-- | opencsv-2.3.jar | bin | 0 -> 19526 bytes | |||
-rw-r--r-- | rb-test.rb | 12 | ||||
-rw-r--r-- | results.txt | 8 |
7 files changed, 51 insertions, 7 deletions
@@ -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(); + } +} @@ -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 @@ -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 Binary files differnew file mode 100644 index 0000000..31fcf30 --- /dev/null +++ b/opencsv-2.3.jar @@ -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) |