lib/rambling/trie/tasks/performance/profile/memory.rb in rambling-trie-0.9.0 vs lib/rambling/trie/tasks/performance/profile/memory.rb in rambling-trie-0.9.1

- old
+ new

@@ -14,65 +14,63 @@ def memory_profile name puts puts name - result = MemoryProfiler.report allow_files: 'lib/rambling/trie', ignore_files: 'tasks/performance' do + result = MemoryProfiler.report allow_files: 'lib/rambling/trie', ignore_files: 'lib/rambling/trie/tasks' do yield end dir = path 'reports', Rambling::Trie::VERSION, 'memory', time FileUtils.mkdir_p dir result.pretty_print to_file: File.join(dir, name) end - def dictionary - dictionary = path 'assets', 'dictionaries', 'words_with_friends.txt' - end - namespace :memory do + desc 'Generate memory profiling reports for creation' task creation: ['performance:directory'] do puts 'Generating memory profiling reports for creation...' trie = nil memory_profile "memory-profile-new-trie" do with_gc_stats { trie = Rambling::Trie.create dictionary } end end + desc 'Generate memory profiling reports for compression' task compression: ['performance:directory'] do trie = Rambling::Trie.create dictionary memory_profile "memory-profile-trie-and-compress" do with_gc_stats { trie.compress! } end with_gc_stats { GC.start } end + desc 'Generate memory profiling reports for lookups' task lookups: ['performance:directory'] do - trie = Rambling::Trie.create dictionary words = %w(hi help beautiful impressionism anthropological) - tries = [ trie, trie.clone.compress! ] - - tries.each do |trie| + trie = Rambling::Trie.create dictionary + compressed_trie = Rambling::Trie.create(dictionary).compress! + [ trie, compressed_trie ].each do |trie| times = 10 - name = "memory-profile-searching-#{trie.compressed? ? 'compressed' : 'uncompressed'}-trie-word" + name = "memory-profile-#{trie.compressed? ? 'compressed' : 'uncompressed'}-trie-word" memory_profile name do with_gc_stats do words.each do |word| times.times do trie.word? word end end end end - name = "memory-profile-searching-#{trie.compressed? ? 'compressed' : 'uncompressed'}-trie-partial-word" + name = "memory-profile-#{trie.compressed? ? 'compressed' : 'uncompressed'}-trie-partial-word" memory_profile name do with_gc_stats do words.each do |word| times.times do trie.partial_word? word @@ -81,21 +79,23 @@ end end end end + desc 'Generate memory profiling reports for scans' task scans: ['performance:directory'] do words = { hi: 1, help: 100, beautiful: 100, impressionism: 200, anthropological: 200, } trie = Rambling::Trie.create dictionary - [ trie, trie.clone.compress! ].each do |trie| + compressed_trie = Rambling::Trie.create(dictionary).compress! + [ trie, compressed_trie ].each do |trie| name = "memory-profile-#{trie.compressed? ? 'compressed' : 'uncompressed'}-trie-scan" memory_profile name do words.each do |word, times| times.times do trie.scan(word.to_s).size @@ -103,14 +103,15 @@ end end end end + desc 'Generate all memory profiling reports' task all: [ - 'performance:profile:memory:creation', - 'performance:profile:memory:compression', - 'performance:profile:memory:lookups', - 'performance:profile:memory:scans' + 'creation', + 'compression', + 'lookups', + 'scans', ] end end end