Created
July 15, 2012 06:42
-
-
Save koseki/3115544 to your computer and use it in GitHub Desktop.
Does Dir.glob("") {} find all files before execute block?
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
#! /bin/env ruby | |
Dir.mkdir "dirs" | |
100.times do |i| | |
puts i | |
Dir.mkdir "dirs/#{i}" | |
1000.times do |j| | |
puts "#{i}/#{j}" | |
Dir.mkdir "dirs/#{i}/#{j}" | |
File.open("dirs/#{i}/#{j}/file", "w") do |io| | |
io << rand.to_s | |
end | |
end | |
end |
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
#! /usr/bin/env ruby | |
# dtrace: print file opend by processes. | |
# dtrace -n 'syscall::open*:entry { printf("%s %s",execname,copyinstr(arg0)); }' | |
puts RUBY_VERSION | |
5.times do | |
first = true | |
start = Time.now.to_f | |
count = 0 | |
puts "---- block ----" | |
Dir.glob("**/*") do |f| | |
if first | |
sleep ARGV[0].to_i if ARGV[0] | |
puts "first: #{Time.now.to_f - start}" | |
first = false | |
else | |
count += 1 | |
end | |
end | |
puts "last: #{Time.now.to_f - start} #{count}" | |
first = true | |
start = Time.now.to_f | |
count = 0 | |
puts "---- each ----" | |
Dir.glob("**/*").to_a.each do |f| | |
if first | |
sleep ARGV[0].to_i if ARGV[0] | |
puts "first: #{Time.now.to_f - start}" | |
first = false | |
else | |
count += 1 | |
end | |
end | |
puts "last: #{Time.now.to_f - start} #{count}" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment