Skip to content

Instantly share code, notes, and snippets.

@igrigorik
Created June 25, 2009 21:48
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 igrigorik/136188 to your computer and use it in GitHub Desktop.
Save igrigorik/136188 to your computer and use it in GitHub Desktop.
# 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