Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
require 'benchmark' MAX = 10000 FILE = 'io_test_bench_file.txt' File.open(FILE, 'w'){ |fh| 1000.times{ |n| fh.puts "This is line: #{n}" } } (ARGV[0] || 5).to_i.times do Benchmark.bm(30) do |x| # Class Methods # x.report('IO.foreach(file)'){ # MAX.times{ IO.foreach(FILE){} } # } x.report('IO.read(file)'){ file = File.open(FILE) MAX.times{ file.read(); file.seek(0) } file.close } # x.report('IO.read(file, 100)'){ # MAX.times{ IO.read(FILE, 100) } # } # x.report('IO.read(file, 100, 20)'){ # MAX.times{ IO.read(FILE, 100, 20) } # } end end File.delete(FILE) if File.exists?(FILE)
This paste will be private.
From the Design Piracy series on my blog: