Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.