alexyoung (owner)

Revisions

gist: 140012 Download_button fork
public
Public Clone URL: git://gist.github.com/140012.git
Embed All Files: show embed
require_benchmarks.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'benchmark'
 
module Kernel
  alias old_require require
 
  def require(path)
    #unless caller.find { |caller_line| caller_line.match /dependencies\.rb/ }
    # return old_require(path)
    #end
 
    output = nil
    @required_files ||= []
 
    benchmark = Benchmark.measure do
      output = old_require path
    end
 
    @required_files << [path, benchmark]
 
    puts path
    caller.each do |caller_line|
      puts "\t#{caller_line}"
    end
    puts ""
 
    #puts "#{path}:"
    #puts loading_benchmark
 
    output
  end
 
  def print_require_benchmark_stats
    puts "Printing benchmark stats:"
    @required_files ||= []
    @required_files.sort! { |a, b| b[1].real <=> a[1].real }
    @required_files.each do |path, benchmark|
      puts path
      puts benchmark
    end
  end
end
 
at_exit { print_require_benchmark_stats }