Skip to content

Instantly share code, notes, and snippets.

@koseki
Created July 15, 2012 06:42
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 koseki/3115544 to your computer and use it in GitHub Desktop.
Save koseki/3115544 to your computer and use it in GitHub Desktop.
Does Dir.glob("") {} find all files before execute block?
#! /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
#! /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