Skip to content

Instantly share code, notes, and snippets.

@waj
Created May 23, 2012 01:43
Show Gist options
  • Save waj/2772782 to your computer and use it in GitHub Desktop.
Save waj/2772782 to your computer and use it in GitHub Desktop.
CSV Parsing: Python vs Ruby
$ time ruby test.rb
10000
20000
...
1000000
real 0m23.596s
user 0m23.354s
sys 0m0.172s
$ time python test.py
10000
20000
...
1000000
real 0m3.663s
user 0m3.498s
sys 0m0.123s
import csv
f = open("/Users/waj/Sandbox/binaria/binaria_gsm_20111101.csv", "r")
i = 0
for row in csv.reader(f, delimiter='|'):
i += 1
if (i % 10000) == 0:
print i
if i == 1000000:
break
require 'csv'
i = 0
CSV.foreach('/Users/waj/Sandbox/binaria/binaria_gsm_20111101.csv', :col_sep => '|', :quote_char => "\0") do |row|
i += 1
puts i if (i % 10000) == 0
break if i == 1000000
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment