Class: Profiler
- Inherits:
-
Object
- Object
- Profiler
- Defined in:
- lib/profile.rb
Constant Summary collapse
- MATCHWORD_COUNT =
2000
Class Method Summary collapse
- .get_tree(keyword_count) ⇒ Object
- .profile_keyword_matching(keyword_count, options = {}) ⇒ Object
- .profile_tree_creation(keyword_count, options = {}) ⇒ Object
Class Method Details
.get_tree(keyword_count) ⇒ Object
10 11 12 13 |
# File 'lib/profile.rb', line 10 def self.get_tree(keyword_count) words = get_random_words(keyword_count) KeywordProspector.new(words) end |
.profile_keyword_matching(keyword_count, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/profile.rb', line 31 def self.profile_keyword_matching(keyword_count, ={}) dl = get_tree(keyword_count) time_limit = [:time_limit] || 300 total = 0 total_matches = 0 start_time = Time.now iterations = 0 words = get_random_words([:count] || MATCHWORD_COUNT) text = words.join(" ") while Time.now - start_time < time_limit matches = 0 start = Time.now dl.process(text) {matches += 1} total += Time.now - start total_matches += matches iterations += 1 end puts "Average time spent matching: #{total/iterations.to_f}" puts "Average number of matches: #{total_matches/iterations.to_f}" end |
.profile_tree_creation(keyword_count, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/profile.rb', line 15 def self.profile_tree_creation(keyword_count, ={}) total = 0 time_limit = [:time_limit] || 0.01 start_time = Time.now iterations = 0 while Time.now - start_time < time_limit start=Time.now get_tree(keyword_count) total += Time.now - start iterations += 1 end puts "Average tree creation time over #{iterations} iterations with #{keyword_count} keywords: #{total/iterations.to_f}" end |