Advertisement
sroller

Benchmark CSV gems

Nov 6th, 2018
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.69 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. #
  3. # test file from the weather station of the University of Waterloo, Ontario, Canada
  4. #
  5.  
  6. require 'httpclient'
  7. require 'csvreader'
  8. require 'csv'
  9. require 'benchmark/ips'
  10.  
  11. URL= 'http://weather.uwaterloo.ca/download/Hobo_15minutedata_2017.csv'
  12. FILE = 'uwaterloo_weatherdata_2017.csv'
  13.  
  14. if not File.exists?(FILE)
  15.   puts "fetch #{URL}"
  16.   http = HTTPClient.new
  17.   csv = http.get_content(URL)
  18.   File.open(FILE, "w") {|f| f.write(csv) }
  19. end
  20.  
  21.  
  22. Benchmark.ips(20) do |x|
  23.     x.report("builtin csv (v#{CSV::VERSION})") { CSV.read(FILE, { headers: true, converters: :all }) }
  24.     x.report("csv reader (v#{CsvReader::VERSION})") { Csv.read(FILE, { headers: true, converters: :all }) }
  25.     x.compare!
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement