Skip to content

Instantly share code, notes, and snippets.

@Phrogz
Created November 15, 2010 23:32
Show Gist options
  • Save Phrogz/701176 to your computer and use it in GitHub Desktop.
Save Phrogz/701176 to your computer and use it in GitHub Desktop.
file = ARGV[0]
2.times do
lines, bytes = 0,0
start = Time.now
contents = File.open(file){ |f| f.read }
contents.scan(/.+/) do |line|
lines += 1
bytes += line.size
end
elapsed = Time.now-start
mb = bytes.to_f / 2**20
puts "File.open(...) read %d lines & %0.1fMB in %0.3fs (%d lines/sec, %0.1fMB/sec)" % [
lines, mb, elapsed, lines/elapsed, mb/elapsed
]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment