Skip to content

Instantly share code, notes, and snippets.

@thbar
Last active December 14, 2015 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thbar/5072198 to your computer and use it in GitHub Desktop.
Save thbar/5072198 to your computer and use it in GitHub Desktop.
Naive benchmark while generating 15M rows of CSV

Code is over here

go1.0.2

[master] thbar@~/git/golang-playground/bulkload: time go run generate_csv.go 

real  0m41.522s
user	0m39.015s
sys	0m1.825s

jruby 1.7.2

[master] thbar@~/git/golang-playground/bulkload: time rake generate_csv

real    1m19.560s
user    1m20.972s
sys    0m4.928s

mri 2.0.0-p0

[master] thbar@~/git/golang-playground/bulkload: time rake generate_csv

real	1m56.004s
user	1m50.204s
sys	0m3.403s

mri 1.9.3-p392

[master] thbar@~/git/golang-playground/bulkload: time rake generate_csv

real    2m0.235s
user	1m55.443s
sys	0m2.993s
@nmerouze
Copy link

nmerouze commented Mar 2, 2013

If you use opencsv (Java lib) instead of the csv (Ruby), you can beat Go with JRuby 1.7.2.

require 'java'
require 'opencsv-2.3.jar'

java_import 'au.com.bytecode.opencsv.CSVWriter'
java_import 'java.io.FileWriter'

writer = CSVWriter.new(FileWriter.new('java-data.csv'), "\t".ord)

writer.writeNext(['guid', 'some_field', 'some_other_field'])

15000000.times do |counter|
  writer.writeNext(["guid_#{counter}", "some_field_#{counter}", "some_other_field_#{counter}"])
end

writer.close

And here's my results (MBA i7 2.0Ghz):

35.15s user
1.48s system
107% cpu
34.031 total

I've got the same time as you for the Go version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment