Created
June 25, 2009 21:48
-
-
Save igrigorik/136188 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.iit.edu/~kbloom1/blog/posix_fadvise.html | |
# http://www.lucas-nussbaum.net/blog/?p=313 | |
# http://rubyforge.org/frs/?group_id=2338&release_id=35811 | |
require 'rubygems' | |
require 'benchmark' | |
require 'fadvise' | |
string = "abcdefghijklmna" | |
1000.times do |n| | |
File.open("#{n}", 'w') { |f| f.puts string*100 } | |
end | |
puts Benchmark.measure("file.fadvise") { | |
fds = [] | |
1000.times do |n| | |
f = File.open("#{n}", "r") | |
f.fadvise 0, 2048, :no_reuse | |
fds.push f | |
end | |
fds.each { |f| | |
f.read | |
} | |
} | |
puts Benchmark.measure("file.read") { | |
1000.times do |n| | |
f = File.open("#{n}", "r") | |
f.read | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment