File: bench_includes.rb

package info (click to toggle)
ruby-facets 2.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 9,824 kB
  • sloc: ruby: 25,483; xml: 90; makefile: 20
file content (25 lines) | stat: -rw-r--r-- 438 bytes parent folder | download
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

$n = 100

puts "Generating #{$n} cascading modules..."

$m = []
(1..$n).each { |i|
  $m[i] = Module.new
  $m[i].class_eval {
    define_method( "_#{i}" ) { puts "Called method in module #{i}." }
    include $m[i-1] if $m[i-1]
  }
}

class ManyIncludes
  include $m[$n]
end

mm = ManyIncludes.new
mn = "_#{$n/2}"

t0 = Time.now
mm.send(mn)
t1 = Time.now
puts "Time to call a single method among #{$n} modules: #{(t1 - t0).to_f} seconds."