Skip to content

Instantly share code, notes, and snippets.

@jonforums
Created March 23, 2010 00:22
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 jonforums/340719 to your computer and use it in GitHub Desktop.
Save jonforums/340719 to your computer and use it in GitHub Desktop.
Benchmark big write
# redmine.ruby-lang.org issue #2742
require 'benchmark'
begin
require 'rbconfig'
puts "(#{RbConfig::CONFIG['host_os']}) #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} \
#{RbConfig::CONFIG['CC']} #{RbConfig::CONFIG['optflags']} #{RbConfig::CONFIG['debugflags']}"
rescue LoadError
end
CHR_COUNT, LINE_DELIM = if ARGV[0] && ARGV[0] == 'lf'
[ 79, "\n" ]
else
[ 78, "\r\n" ]
end
Benchmark.bm(9) do |x|
x.report("big_write") do
File.open("big_foo.txt", 'wb') do |f|
625_000.times { f.write('-' * CHR_COUNT << LINE_DELIM) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment