File: bench_compiled_load.rb

package info (click to toggle)
jruby 1.5.1-1%2Bdeb6u1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze-lts
  • size: 47,024 kB
  • ctags: 74,144
  • sloc: ruby: 398,155; java: 169,506; yacc: 3,782; xml: 2,469; ansic: 415; sh: 279; makefile: 78; tcl: 40
file content (95 lines) | stat: -rw-r--r-- 2,923 bytes parent folder | download | duplicates (4)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require 'benchmark'
jrubyc = "jruby jrubyc"

def jrubyc(file)
    system "jrubyc -p 'ruby' #{file}"
end

def bench_compiled_load(bm)
  File.open('compiled_load_test_simple.rb', 'w') do |f|
    f.write '1'
  end
  File.open('compiled_load_test_simple_strings.rb', 'w') do |f|
    f.write '"foo"'
  end
  File.open('compiled_load_test_complex_flat.rb', 'w') do |f|
    f.write "
if false
#{"  foo 1\n" * 1000}
#{"  'asdf'\n" * 1000}
end
    "
  end
  File.open('compiled_load_test_complex_tree.rb', 'w') do |f|
    f.write "
if false
#{("def foo; " + ('1; ' * 100) + "end\n") * 10}
#{("def foo; " + ('"asdf"; ' * 100) + "end\n") * 10}
end
    "
  end
  
  File.open('compiled_load_test_many_defs.rb', 'w') do |f|
    f.write "
      def foo; end
      def bar; end
      def oof; end
      def rab; end
  "
  end
  
  jrubyc 'compiled_load_test_simple.rb'
  jrubyc 'compiled_load_test_simple_strings.rb'
  jrubyc 'compiled_load_test_complex_flat.rb'
  jrubyc 'compiled_load_test_complex_tree.rb'
  jrubyc 'compiled_load_test_many_defs.rb'
#  
  $: << '.'
  bm.report("control, 1000.times") { 1000.times {1} }

  bm.report("control, 10000 loads simple") do
    10000.times { load 'compiled_load_test_simple.rb' }
  end
  bm.report("control, 10000 loads simple_strings") do
    10000.times { load 'compiled_load_test_simple_strings.rb' }
  end
  bm.report("control, 100 loads complex flat") do
    100.times { load 'compiled_load_test_complex_flat.rb' }
  end
  bm.report("control, 100 loads complex tree") do
    100.times { load 'compiled_load_test_complex_tree.rb' }
  end
  bm.report("control, 1000 loads many defs") do
    1000.times { load 'compiled_load_test_many_defs.rb' }
  end

  bm.report("10000 loads simple compiled") do
    10000.times { load 'ruby/compiled_load_test_simple.class' }
  end
  bm.report("10000 loads simple strings compiled") do
    10000.times { load 'ruby/compiled_load_test_simple_strings.class' }
  end
  bm.report("100 loads complex flat compiled") do
    100.times { load 'ruby/compiled_load_test_complex_flat.class' }
  end
  bm.report("100 loads complex tree compiled") do
    100.times { load 'ruby/compiled_load_test_complex_tree.class' }
  end
  bm.report("1000 loads many defs compiled") do
    1000.times { load 'ruby/compiled_load_test_many_defs.class' }
  end
end

if __FILE__ == $0
  Benchmark.bmbm {|bm| bench_compiled_load(bm)}
  File.delete("compiled_load_test_simple.rb")
  File.delete("compiled_load_test_simple_strings.rb")
  File.delete("compiled_load_test_complex_flat.rb")
  File.delete("compiled_load_test_complex_tree.rb")
  File.delete("compiled_load_test_many_defs.rb")
  File.delete("ruby/compiled_load_test_simple.class")
  File.delete("ruby/compiled_load_test_simple_strings.class")
  File.delete("ruby/compiled_load_test_complex_flat.class")
  File.delete("ruby/compiled_load_test_complex_tree.class")
  File.delete("ruby/compiled_load_test_many_defs.class")  
end