aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bench.rb13
-rw-r--r--csv-test.py16
-rw-r--r--csv-test.rb12
-rw-r--r--gen.rb10
4 files changed, 51 insertions, 0 deletions
diff --git a/bench.rb b/bench.rb
new file mode 100644
index 0000000..e34bcda
--- /dev/null
+++ b/bench.rb
@@ -0,0 +1,13 @@
+#!/usr/bin/env ruby
+
+require 'benchmark'
+
+Benchmark.bm(5) do |bm|
+ bm.report('python') do
+ `python2.7 ./csv-test.py test.csv out.csv`
+ end
+
+ bm.report('ruby') do
+ `ruby ./csv-test.rb test.csv out.csv`
+ end
+end
diff --git a/csv-test.py b/csv-test.py
new file mode 100644
index 0000000..0662965
--- /dev/null
+++ b/csv-test.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python2.7
+
+import sys
+import csv
+
+with open(sys.argv[1], 'rb') as src_file:
+ # create csv reader
+ src = csv.reader(src_file)
+
+ with open(sys.argv[2], 'wb') as dst_file:
+ # create csv writer
+ dst = csv.writer(dst_file)
+
+ # walk, mutate, and write rows
+ for row in src:
+ dst.writerow(row + (['foo'] * 2))
diff --git a/csv-test.rb b/csv-test.rb
new file mode 100644
index 0000000..c0e43c0
--- /dev/null
+++ b/csv-test.rb
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+
+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
+ end
+end
diff --git a/gen.rb b/gen.rb
new file mode 100644
index 0000000..1d0af5d
--- /dev/null
+++ b/gen.rb
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+
+require 'csv'
+
+CSV.open(ARGV.shift, 'wb') do |csv|
+ 20_000_000.times do |i|
+ csv << [i, 'blum', 'baz']
+ end
+end
+