Project

General

Profile

Bug #13167 ยป bench_dir_glob.rb

h.shirosaki (Hiroshi Shirosaki), 09/11/2017 09:58 AM

 
1
require 'benchmark/ips'
2
require 'fileutils'
3

    
4
# setup directories
5
ROOT = /mingw/ =~ RUBY_PLATFORM ? 'v:' : '/tmp'
6
BASE_DIR = "#{ROOT}/test/myapp/app/views/common"
7
FileUtils.mkdir_p(BASE_DIR)
8
%w(_menu_stats.html.erb _menu_stats.en.html.erb).each do |path|
9
  FileUtils.touch("#{BASE_DIR}/#{path}")
10
end
11
20.times do |i|
12
  FileUtils.touch("#{BASE_DIR}/../#{i}")
13
  FileUtils.touch("#{BASE_DIR}/#{i}")
14
end
15

    
16
p BRACES_PATTERN = "#{ROOT}/test/myapp/app/views/common/_menu_stats{.en,}{.html,}{}{.erb,.builder,.raw,.ruby,.jbuilder,.coffee,}"
17
p RECURSIVE_PATTERN = "#{ROOT}/test/myapp/app/views/**/_menu_stats{.en,}{.html,}{}{.erb,.builder,.raw,.ruby,.jbuilder,.coffee,}"
18

    
19
Benchmark.ips do |x|
20
  x.report("braces") do
21
    Dir.glob(BRACES_PATTERN)
22
  end
23
  x.report("recursive") do
24
    Dir.glob(RECURSIVE_PATTERN)
25
  end
26
end
27

    
28
# cleanup
29
FileUtils.rm_rf("#{ROOT}/test")