test/unit/test_ccsv.rb in ccsv-0.0.2 vs test/unit/test_ccsv.rb in ccsv-0.1
- old
+ new
@@ -1,10 +1,29 @@
require 'test/unit'
require 'ccsv'
-require 'csv'
+require 'benchmark'
+# Yeah, I know.
+begin
+ require 'csv'
+ require 'rubygems'
+ require 'fastercsv'
+ require 'lightcsv'
+ require 'csvscan'
+
+ module CSVScan
+ def self.foreach(file, &block)
+ open(file) do |f|
+ scan(f, &block)
+ end
+ end
+ end
+
+rescue LoadError
+end
+
class TestCcsv < Test::Unit::TestCase
def setup
@dir = "#{File.dirname(__FILE__)}/../"
end
@@ -28,13 +47,15 @@
end
assert_equal csv, ccsv
end
def test_speed
- start = Time.now
- Ccsv.foreach(@dir + "data.csv") do |values|
+ [Ccsv, FasterCSV, CSV].each do |klass| # CSVScan, LightCsv,
+ Benchmark.bm do |x|
+ x.report(klass.name) do
+ klass.foreach(@dir + "data.csv") do |values| end
+ end
+ end
end
- dur = Time.now - start
- puts "\n#{dur} seconds\n"
end
end