ruby-prof 0.8.1-x86-mingw32 → 0.11.0.rc1-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. data/CHANGES +89 -13
  2. data/LICENSE +4 -3
  3. data/{README → README.rdoc} +155 -162
  4. data/Rakefile +50 -123
  5. data/bin/ruby-prof +86 -47
  6. data/examples/empty.png +0 -0
  7. data/examples/graph.dot +106 -0
  8. data/examples/graph.png +0 -0
  9. data/examples/minus.png +0 -0
  10. data/examples/multi.flat.txt +23 -0
  11. data/examples/multi.graph.html +906 -0
  12. data/examples/multi.grind.dat +194 -0
  13. data/examples/multi.stack.html +573 -0
  14. data/examples/plus.png +0 -0
  15. data/examples/stack.html +573 -0
  16. data/ext/ruby_prof/extconf.rb +53 -0
  17. data/ext/ruby_prof/rp_call_info.c +369 -0
  18. data/ext/ruby_prof/rp_call_info.h +46 -0
  19. data/ext/ruby_prof/rp_measure.c +48 -0
  20. data/ext/ruby_prof/rp_measure.h +45 -0
  21. data/ext/ruby_prof/rp_measure_allocations.c +86 -0
  22. data/ext/ruby_prof/rp_measure_cpu_time.c +112 -0
  23. data/ext/ruby_prof/rp_measure_gc_runs.c +87 -0
  24. data/ext/ruby_prof/rp_measure_gc_time.c +73 -0
  25. data/ext/ruby_prof/rp_measure_memory.c +81 -0
  26. data/ext/ruby_prof/rp_measure_process_time.c +71 -0
  27. data/ext/ruby_prof/rp_measure_wall_time.c +42 -0
  28. data/ext/ruby_prof/rp_method.c +363 -0
  29. data/ext/ruby_prof/rp_method.h +55 -0
  30. data/ext/ruby_prof/rp_stack.c +61 -0
  31. data/ext/ruby_prof/rp_stack.h +40 -0
  32. data/ext/ruby_prof/rp_thread.c +113 -0
  33. data/ext/ruby_prof/rp_thread.h +20 -0
  34. data/ext/ruby_prof/ruby_prof.c +332 -1377
  35. data/ext/ruby_prof/ruby_prof.h +54 -188
  36. data/ext/ruby_prof/version.h +6 -3
  37. data/lib/1.8/ruby_prof.so +0 -0
  38. data/lib/1.9/ruby_prof.exp +0 -0
  39. data/lib/1.9/ruby_prof.ilk +0 -0
  40. data/lib/1.9/ruby_prof.lib +0 -0
  41. data/lib/1.9/ruby_prof.pdb +0 -0
  42. data/lib/1.9/ruby_prof.so +0 -0
  43. data/lib/ruby-prof.rb +32 -18
  44. data/lib/ruby-prof/abstract_printer.rb +15 -5
  45. data/lib/ruby-prof/aggregate_call_info.rb +11 -3
  46. data/lib/ruby-prof/call_info.rb +68 -1
  47. data/lib/ruby-prof/call_stack_printer.rb +775 -0
  48. data/lib/ruby-prof/call_tree_printer.rb +17 -9
  49. data/lib/ruby-prof/compatibility.rb +134 -0
  50. data/lib/ruby-prof/dot_printer.rb +152 -0
  51. data/lib/ruby-prof/empty.png +0 -0
  52. data/lib/ruby-prof/flat_printer.rb +23 -24
  53. data/lib/ruby-prof/flat_printer_with_line_numbers.rb +17 -21
  54. data/lib/ruby-prof/graph_html_printer.rb +69 -39
  55. data/lib/ruby-prof/graph_printer.rb +35 -35
  56. data/lib/ruby-prof/method_info.rb +26 -4
  57. data/lib/ruby-prof/minus.png +0 -0
  58. data/lib/ruby-prof/multi_printer.rb +56 -0
  59. data/lib/ruby-prof/plus.png +0 -0
  60. data/lib/ruby-prof/profile.rb +72 -0
  61. data/lib/ruby-prof/rack.rb +31 -0
  62. data/lib/ruby-prof/symbol_to_proc.rb +3 -1
  63. data/lib/ruby-prof/task.rb +20 -19
  64. data/lib/ruby-prof/test.rb +5 -3
  65. data/lib/ruby_prof.exp +0 -0
  66. data/lib/ruby_prof.ilk +0 -0
  67. data/lib/ruby_prof.lib +0 -0
  68. data/lib/ruby_prof.pdb +0 -0
  69. data/lib/ruby_prof.so +0 -0
  70. data/lib/unprof.rb +2 -0
  71. data/test/aggregate_test.rb +29 -14
  72. data/test/basic_test.rb +3 -251
  73. data/test/bug_test.rb +6 -0
  74. data/test/duplicate_names_test.rb +4 -4
  75. data/test/dynamic_method_test.rb +61 -0
  76. data/test/enumerable_test.rb +4 -4
  77. data/test/exceptions_test.rb +6 -5
  78. data/test/exclude_threads_test.rb +47 -47
  79. data/test/exec_test.rb +5 -5
  80. data/test/line_number_test.rb +16 -16
  81. data/test/measure_allocations_test.rb +25 -0
  82. data/test/measure_cpu_time_test.rb +212 -0
  83. data/test/measure_gc_runs_test.rb +29 -0
  84. data/test/measure_gc_time_test.rb +29 -0
  85. data/test/measure_memory_test.rb +36 -0
  86. data/test/measure_process_time_test.rb +205 -0
  87. data/test/measure_wall_time_test.rb +209 -0
  88. data/test/method_elimination_test.rb +74 -0
  89. data/test/module_test.rb +12 -21
  90. data/test/multi_printer_test.rb +81 -0
  91. data/test/no_method_class_test.rb +5 -3
  92. data/test/prime.rb +7 -10
  93. data/test/prime_test.rb +3 -3
  94. data/test/printers_test.rb +180 -54
  95. data/test/recursive_test.rb +34 -72
  96. data/test/singleton_test.rb +5 -4
  97. data/test/stack_printer_test.rb +73 -0
  98. data/test/stack_test.rb +7 -7
  99. data/test/start_stop_test.rb +23 -6
  100. data/test/test_helper.rb +81 -0
  101. data/test/test_suite.rb +35 -21
  102. data/test/thread_test.rb +40 -39
  103. data/test/unique_call_path_test.rb +6 -6
  104. metadata +106 -51
  105. data/ext/ruby_prof/measure_allocations.h +0 -58
  106. data/ext/ruby_prof/measure_cpu_time.h +0 -152
  107. data/ext/ruby_prof/measure_gc_runs.h +0 -76
  108. data/ext/ruby_prof/measure_gc_time.h +0 -57
  109. data/ext/ruby_prof/measure_memory.h +0 -101
  110. data/ext/ruby_prof/measure_process_time.h +0 -52
  111. data/ext/ruby_prof/measure_wall_time.h +0 -53
  112. data/ext/ruby_prof/mingw/Rakefile +0 -23
  113. data/ext/ruby_prof/mingw/build.rake +0 -38
  114. data/rails/environment/profile.rb +0 -24
  115. data/rails/example/example_test.rb +0 -9
  116. data/rails/profile_test_helper.rb +0 -21
  117. data/test/current_failures_windows +0 -8
  118. data/test/measurement_test.rb +0 -121
  119. data/test/ruby-prof-bin +0 -20
@@ -0,0 +1,209 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+
6
+ class MeasureWallTimeTest < Test::Unit::TestCase
7
+ def setup
8
+ # Need to use wall time for this test due to the sleep calls
9
+ RubyProf::measure_mode = RubyProf::WALL_TIME
10
+ end
11
+
12
+ def test_mode
13
+ RubyProf::measure_mode = RubyProf::WALL_TIME
14
+ assert_equal(RubyProf::WALL_TIME, RubyProf::measure_mode)
15
+ end
16
+
17
+ def test_wall_time_enabled_defined
18
+ assert(defined?(RubyProf::WALL_TIME_ENABLED))
19
+ end
20
+
21
+ def test_class_methods
22
+ result = RubyProf.profile do
23
+ RubyProf::C1.hello
24
+ end
25
+
26
+ # Length should be 3:
27
+ # MeasureWallTimeTest#test_class_methods
28
+ # <Class::RubyProf::C1>#hello
29
+ # Kernel#sleep
30
+
31
+ methods = result.threads.values.first.sort.reverse
32
+ assert_equal(3, methods.length)
33
+
34
+ # Check the names
35
+ assert_equal('MeasureWallTimeTest#test_class_methods', methods[0].full_name)
36
+ assert_equal('<Class::RubyProf::C1>#hello', methods[1].full_name)
37
+ assert_equal('Kernel#sleep', methods[2].full_name)
38
+
39
+ # Check times
40
+ assert_in_delta(0.1, methods[0].total_time, 0.01)
41
+ assert_in_delta(0, methods[0].wait_time, 0.01)
42
+ assert_in_delta(0, methods[0].self_time, 0.01)
43
+
44
+ assert_in_delta(0.1, methods[1].total_time, 0.01)
45
+ assert_in_delta(0, methods[1].wait_time, 0.01)
46
+ assert_in_delta(0, methods[1].self_time, 0.01)
47
+
48
+ assert_in_delta(0.1, methods[2].total_time, 0.01)
49
+ assert_in_delta(0, methods[2].wait_time, 0.01)
50
+ assert_in_delta(0.1, methods[2].self_time, 0.01)
51
+ end
52
+
53
+ def test_instance_methods
54
+ result = RubyProf.profile do
55
+ RubyProf::C1.new.hello
56
+ end
57
+
58
+ # Methods called
59
+ # MeasureWallTimeTest#test_instance_methods
60
+ # Class.new
61
+ # Class:Object#allocate
62
+ # for Object#initialize
63
+ # C1#hello
64
+ # Kernel#sleep
65
+
66
+ methods = result.threads.values.first.sort.reverse
67
+ assert_equal(6, methods.length)
68
+ names = methods.map(&:full_name)
69
+ assert_equal('MeasureWallTimeTest#test_instance_methods', names[0])
70
+ assert_equal('RubyProf::C1#hello', names[1])
71
+ assert_equal('Kernel#sleep', names[2])
72
+ assert_equal('Class#new', names[3])
73
+ # order can differ
74
+ assert(names.include?("<Class::#{RubyProf::PARENT}>#allocate"))
75
+ assert(names.include?("#{RubyProf::PARENT}#initialize"))
76
+
77
+ # Check times
78
+ assert_in_delta(0.2, methods[0].total_time, 0.02)
79
+ assert_in_delta(0, methods[0].wait_time, 0.02)
80
+ assert_in_delta(0, methods[0].self_time, 0.02)
81
+
82
+ assert_in_delta(0.2, methods[1].total_time, 0.02)
83
+ assert_in_delta(0, methods[1].wait_time, 0.02)
84
+ assert_in_delta(0, methods[1].self_time, 0.02)
85
+
86
+ assert_in_delta(0.2, methods[2].total_time, 0.02)
87
+ assert_in_delta(0, methods[2].wait_time, 0.02)
88
+ assert_in_delta(0.2, methods[2].self_time, 0.02)
89
+
90
+ assert_in_delta(0, methods[3].total_time, 0.01)
91
+ assert_in_delta(0, methods[3].wait_time, 0.01)
92
+ assert_in_delta(0, methods[3].self_time, 0.01)
93
+
94
+ assert_in_delta(0, methods[4].total_time, 0.01)
95
+ assert_in_delta(0, methods[4].wait_time, 0.01)
96
+ assert_in_delta(0, methods[4].self_time, 0.01)
97
+
98
+ assert_in_delta(0, methods[5].total_time, 0.01)
99
+ assert_in_delta(0, methods[5].wait_time, 0.01)
100
+ assert_in_delta(0, methods[5].self_time, 0.01)
101
+ end
102
+
103
+ def test_module_methods
104
+ result = RubyProf.profile do
105
+ RubyProf::C2.hello
106
+ end
107
+
108
+ # Methods:
109
+ # MeasureWallTimeTest#test_module_methods
110
+ # M1#hello
111
+ # Kernel#sleep
112
+
113
+ methods = result.threads.values.first.sort.reverse
114
+ assert_equal(3, methods.length)
115
+
116
+ assert_equal('MeasureWallTimeTest#test_module_methods', methods[0].full_name)
117
+ assert_equal('RubyProf::M1#hello', methods[1].full_name)
118
+ assert_equal('Kernel#sleep', methods[2].full_name)
119
+
120
+ # Check times
121
+ assert_in_delta(0.3, methods[0].total_time, 0.1)
122
+ assert_in_delta(0, methods[0].wait_time, 0.02)
123
+ assert_in_delta(0, methods[0].self_time, 0.02)
124
+
125
+ assert_in_delta(0.3, methods[1].total_time, 0.1)
126
+ assert_in_delta(0, methods[1].wait_time, 0.02)
127
+ assert_in_delta(0, methods[1].self_time, 0.02)
128
+
129
+ assert_in_delta(0.3, methods[2].total_time, 0.1)
130
+ assert_in_delta(0, methods[2].wait_time, 0.02)
131
+ assert_in_delta(0.3, methods[2].self_time, 0.1)
132
+ end
133
+
134
+ def test_module_instance_methods
135
+ result = RubyProf.profile do
136
+ RubyProf::C2.new.hello
137
+ end
138
+
139
+ # Methods:
140
+ # MeasureWallTimeTest#test_module_instance_methods
141
+ # Class#new
142
+ # <Class::Object>#allocate
143
+ # Object#initialize
144
+ # M1#hello
145
+ # Kernel#sleep
146
+
147
+ methods = result.threads.values.first.sort.reverse
148
+ assert_equal(6, methods.length)
149
+ names = methods.map(&:full_name)
150
+ assert_equal('MeasureWallTimeTest#test_module_instance_methods', names[0])
151
+ assert_equal('RubyProf::M1#hello', names[1])
152
+ assert_equal('Kernel#sleep', names[2])
153
+ assert_equal('Class#new', names[3])
154
+ assert(names.include?("<Class::#{RubyProf::PARENT}>#allocate"))
155
+ assert(names.include?("#{RubyProf::PARENT}#initialize"))
156
+
157
+ # Check times
158
+ assert_in_delta(0.3, methods[0].total_time, 0.1)
159
+ assert_in_delta(0, methods[0].wait_time, 0.1)
160
+ assert_in_delta(0, methods[0].self_time, 0.1)
161
+
162
+ assert_in_delta(0.3, methods[1].total_time, 0.02)
163
+ assert_in_delta(0, methods[1].wait_time, 0.01)
164
+ assert_in_delta(0, methods[1].self_time, 0.01)
165
+
166
+ assert_in_delta(0.3, methods[2].total_time, 0.02)
167
+ assert_in_delta(0, methods[2].wait_time, 0.01)
168
+ assert_in_delta(0.3, methods[2].self_time, 0.02)
169
+
170
+ assert_in_delta(0, methods[3].total_time, 0.01)
171
+ assert_in_delta(0, methods[3].wait_time, 0.01)
172
+ assert_in_delta(0, methods[3].self_time, 0.01)
173
+
174
+ assert_in_delta(0, methods[4].total_time, 0.01)
175
+ assert_in_delta(0, methods[4].wait_time, 0.01)
176
+ assert_in_delta(0, methods[4].self_time, 0.01)
177
+
178
+ assert_in_delta(0, methods[5].total_time, 0.01)
179
+ assert_in_delta(0, methods[5].wait_time, 0.01)
180
+ assert_in_delta(0, methods[5].self_time, 0.01)
181
+ end
182
+
183
+ def test_singleton
184
+ c3 = RubyProf::C3.new
185
+
186
+ class << c3
187
+ def hello
188
+ end
189
+ end
190
+
191
+ result = RubyProf.profile do
192
+ c3.hello
193
+ end
194
+
195
+ methods = result.threads.values.first.sort.reverse
196
+ assert_equal(2, methods.length)
197
+
198
+ assert_equal('MeasureWallTimeTest#test_singleton', methods[0].full_name)
199
+ assert_equal('<Object::RubyProf::C3>#hello', methods[1].full_name)
200
+
201
+ assert_in_delta(0, methods[0].total_time, 0.01)
202
+ assert_in_delta(0, methods[0].wait_time, 0.01)
203
+ assert_in_delta(0, methods[0].self_time, 0.01)
204
+
205
+ assert_in_delta(0, methods[1].total_time, 0.01)
206
+ assert_in_delta(0, methods[1].wait_time, 0.01)
207
+ assert_in_delta(0, methods[1].self_time, 0.01)
208
+ end
209
+ end
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require 'tmpdir'
6
+
7
+ # Test data
8
+ # A
9
+ # / \
10
+ # B C
11
+ # \
12
+ # B
13
+
14
+ class ESTPT
15
+ def a
16
+ 100.times{b}
17
+ 300.times{c}
18
+ c;c;c
19
+ end
20
+
21
+ def b
22
+ sleep 0
23
+ end
24
+
25
+ def c
26
+ 5.times{b}
27
+ end
28
+ end
29
+
30
+ class MethodEliminationTest < Test::Unit::TestCase
31
+ def setup
32
+ # Need to use wall time for this test due to the sleep calls
33
+ RubyProf::measure_mode = RubyProf::WALL_TIME
34
+ end
35
+
36
+ def test_setting_parent
37
+ result = RubyProf.profile do
38
+ 1000.times { 1+1 }
39
+ end
40
+ method_infos = result.threads.values.first
41
+ assert(m1 = method_infos[0])
42
+ assert(c1 = m1.call_infos.first)
43
+ assert_equal(c1, c1.parent = c1)
44
+ assert_equal c1, c1.parent
45
+ end
46
+
47
+ def test_methods_can_be_eliminated
48
+ RubyProf.start
49
+ 5.times{ESTPT.new.a}
50
+ result = RubyProf.stop
51
+ # result.dump
52
+ eliminated = result.eliminate_methods!([/Integer#times/])
53
+ # puts eliminated.inspect
54
+ # result.dump
55
+ eliminated.each do |m|
56
+ assert_method_has_been_eliminated(result, m)
57
+ end
58
+ end
59
+
60
+ private
61
+ def assert_method_has_been_eliminated(result, eliminated_method)
62
+ result.threads.each do |thread_id, methods|
63
+ methods.each do |method|
64
+ method.call_infos.each do |ci|
65
+ assert(ci.target != eliminated_method, "broken self")
66
+ assert(ci.parent.target != eliminated_method, "broken parent") if ci.parent
67
+ ci.children.each do |callee|
68
+ assert(callee.target != eliminated_method, "broken kid")
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
data/test/module_test.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- require 'test/unit'
3
- require 'ruby-prof'
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
4
5
 
5
6
  # Need to use wall time for this test due to the sleep calls
6
7
  RubyProf::measure_mode = RubyProf::WALL_TIME
@@ -16,7 +17,7 @@ module Bar
16
17
  sleep(0.5)
17
18
  Foo::hello
18
19
  end
19
-
20
+
20
21
  def hello
21
22
  sleep(0.5)
22
23
  Bar::hello
@@ -31,24 +32,14 @@ class ModuleTest < Test::Unit::TestCase
31
32
  hello
32
33
  end
33
34
 
34
- methods = result.threads.values.first.sort.reverse
35
-
35
+ methods = result.threads.values.first
36
+
36
37
  # Length should be 5
37
38
  assert_equal(5, methods.length)
38
-
39
- method = methods[0]
40
- assert_equal('ModuleTest#test_nested_modules', method.full_name)
41
-
42
- method = methods[1]
43
- assert_equal('Bar#hello', method.full_name)
44
-
45
- method = methods[2]
46
- assert_equal('Kernel#sleep', method.full_name)
47
-
48
- method = methods[3]
49
- assert_equal('<Module::Bar>#hello', method.full_name)
50
-
51
- method = methods[4]
52
- assert_equal('<Module::Foo>#hello', method.full_name)
53
- end
39
+
40
+ # these methods should be in there... (hard to tell order though).
41
+ for name in ['ModuleTest#test_nested_modules','Bar#hello','Kernel#sleep','<Module::Bar>#hello','<Module::Foo>#hello']
42
+ assert methods.map(&:full_name).include?( name )
43
+ end
44
+ end
54
45
  end
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require 'tmpdir'
6
+
7
+ # Test data
8
+ # A
9
+ # / \
10
+ # B C
11
+ # \
12
+ # B
13
+
14
+ class MSTPT
15
+ def a
16
+ 100.times{b}
17
+ 300.times{c}
18
+ c;c;c
19
+ end
20
+
21
+ def b
22
+ sleep 0
23
+ end
24
+
25
+ def c
26
+ 5.times{b}
27
+ end
28
+ end
29
+
30
+ class MultiPrinterTest < Test::Unit::TestCase
31
+ def setup
32
+ # Need to use wall time for this test due to the sleep calls
33
+ RubyProf::measure_mode = RubyProf::WALL_TIME
34
+ end
35
+
36
+ def test_all_profiles_can_be_created
37
+ start_time = Time.now
38
+ RubyProf.start
39
+ 5.times{MSTPT.new.a}
40
+ result = RubyProf.stop
41
+ end_time = Time.now
42
+ expected_time = end_time - start_time
43
+ stack = graph = nil
44
+ assert_nothing_raised { stack, graph = print(result) }
45
+ re = Regexp.new('
46
+ \s*<table>
47
+ \s*<tr>
48
+ \s*<th>Thread ID</th>
49
+ \s*<th>Total Time</th>
50
+ \s*</tr>
51
+ \s*
52
+ \s*<tr>
53
+ \s*<td><a href="#\d+">\d+</a></td>
54
+ \s*<td>([\.0-9]+)</td>
55
+ \s*</tr>
56
+ \s*
57
+ \s*</table>')
58
+ assert graph =~ re
59
+ display_time = $1.to_f
60
+ difference = (expected_time-display_time).abs
61
+ assert_in_delta expected_time, display_time, 0.005
62
+ end
63
+
64
+ private
65
+ def print(result)
66
+ test = caller.first =~ /in `(.*)'/ ? $1 : "test"
67
+ path = Dir::tmpdir
68
+ profile = "ruby_prof_#{test}"
69
+ printer = RubyProf::MultiPrinter.new(result)
70
+ printer.print(:path => path, :profile => profile,
71
+ :threshold => 0, :min_percent => 0, :title => "ruby_prof #{test}")
72
+ if RUBY_PLATFORM =~ /darwin/ && ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT']=="1"
73
+ system("open '#{printer.stack_profile}'")
74
+ end
75
+ if GC.respond_to?(:dump_file_and_line_info)
76
+ GC.start
77
+ GC.dump_file_and_line_info("heap.dump")
78
+ end
79
+ [File.open(printer.stack_profile){|f|f.read}, File.open(printer.graph_profile){|f|f.read}]
80
+ end
81
+ end
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- require 'ruby-prof'
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
3
5
 
4
6
  # Make sure this works with no class or method
5
- result = RubyProf.profile do
7
+ result = RubyProf.profile do
6
8
  sleep 1
7
9
  end
8
10
 
@@ -10,4 +12,4 @@ methods = result.threads.values.first
10
12
  global_method = methods.sort_by {|method| method.full_name}.first
11
13
  if global_method.full_name != 'Global#[No method]'
12
14
  raise(RuntimeError, "Wrong method name. Expected: Global#[No method]. Actual: #{global_method.full_name}")
13
- end
15
+ end
data/test/prime.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # A silly little test program that finds prime numbers. It
2
2
  # is intentionally badly designed to show off the use
3
3
  # of ruby-prof.
4
- #
4
+ #
5
5
  # Source from http://people.cs.uchicago.edu/~bomb154/154/maclabs/profilers-lab/
6
6
 
7
7
  def make_random_array(length, maxnum)
@@ -9,10 +9,10 @@ def make_random_array(length, maxnum)
9
9
  result.each_index do |i|
10
10
  result[i] = rand(maxnum)
11
11
  end
12
-
12
+
13
13
  result
14
14
  end
15
-
15
+
16
16
  def is_prime(x)
17
17
  y = 2
18
18
  y.upto(x-1) do |i|
@@ -43,16 +43,13 @@ def find_largest(primes)
43
43
  largest
44
44
  end
45
45
 
46
- def run_primes
47
- length = 10
48
- maxnum = 1000
49
-
46
+ def run_primes(length=10, maxnum=1000)
50
47
  # Create random numbers
51
48
  random_array = make_random_array(length, maxnum)
52
-
49
+
53
50
  # Find the primes
54
51
  primes = find_primes(random_array)
55
-
52
+
56
53
  # Find the largest primes
57
54
  # largest = find_largest(primes)
58
- end
55
+ end