From 73bce6b2090b501cd9e2fa20ec1e22ea291bb177 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 31 Aug 2016 17:22:57 -0400 Subject: commit outstanding changes --- .gitignore | 1 + bench.rb | 8 ++++++-- cr-test.cr | 16 ++++++++++++++++ csv-test.py | 16 ---------------- csv-test.rb | 12 ------------ py-test.py | 16 ++++++++++++++++ rb-test.rb | 12 ++++++++++++ 7 files changed, 51 insertions(+), 30 deletions(-) create mode 100644 .gitignore mode change 100644 => 100755 bench.rb create mode 100644 cr-test.cr delete mode 100644 csv-test.py delete mode 100644 csv-test.rb create mode 100644 py-test.py create mode 100644 rb-test.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..72699f7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/*.csv diff --git a/bench.rb b/bench.rb old mode 100644 new mode 100755 index e34bcda..83f4113 --- a/bench.rb +++ b/bench.rb @@ -4,10 +4,14 @@ require 'benchmark' Benchmark.bm(5) do |bm| bm.report('python') do - `python2.7 ./csv-test.py test.csv out.csv` + `python2.7 ./py-test.py test.csv out.csv` end bm.report('ruby') do - `ruby ./csv-test.rb test.csv out.csv` + `ruby ./rb-test.rb test.csv out.csv` + end + + bm.report('crystal') do + `./cr-test test.csv out.csv` end end diff --git a/cr-test.cr b/cr-test.cr new file mode 100644 index 0000000..18c6580 --- /dev/null +++ b/cr-test.cr @@ -0,0 +1,16 @@ +# build: crystal build --release cr-test.cr + +require "csv" + +# get paths +src_path, dst_path = ARGV + +File.open(src_path, "rb") do |src_io| + File.open(dst_path, "wb") do |dst_io| + CSV.build(dst_io) do |dst| + CSV.each_row(src_io) do |row| + dst.row(row += (%w{foo} * 2)) + end + end + end +end diff --git a/csv-test.py b/csv-test.py deleted file mode 100644 index 0662965..0000000 --- a/csv-test.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/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 deleted file mode 100644 index c0e43c0..0000000 --- a/csv-test.rb +++ /dev/null @@ -1,12 +0,0 @@ -#!/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/py-test.py b/py-test.py new file mode 100644 index 0000000..0662965 --- /dev/null +++ b/py-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/rb-test.rb b/rb-test.rb new file mode 100644 index 0000000..973c8cf --- /dev/null +++ b/rb-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 -- cgit v1.2.3