rambling-trie 0.9.3 → 1.0.0
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.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/LICENSE +1 -1
- data/README.md +133 -26
- data/Rakefile +1 -2
- data/lib/rambling/trie.rb +53 -9
- data/lib/rambling/trie/comparable.rb +16 -0
- data/lib/rambling/trie/compressable.rb +14 -0
- data/lib/rambling/trie/compressed_node.rb +38 -14
- data/lib/rambling/trie/compressor.rb +14 -10
- data/lib/rambling/trie/configuration.rb +11 -0
- data/lib/rambling/trie/configuration/properties.rb +66 -0
- data/lib/rambling/trie/configuration/provider_collection.rb +101 -0
- data/lib/rambling/trie/container.rb +57 -17
- data/lib/rambling/trie/enumerable.rb +1 -1
- data/lib/rambling/trie/forwardable.rb +9 -4
- data/lib/rambling/trie/inspectable.rb +37 -0
- data/lib/rambling/trie/invalid_operation.rb +3 -2
- data/lib/rambling/trie/missing_node.rb +2 -1
- data/lib/rambling/trie/node.rb +40 -30
- data/lib/rambling/trie/raw_node.rb +29 -13
- data/lib/rambling/trie/readers.rb +11 -0
- data/lib/rambling/trie/readers/plain_text.rb +26 -0
- data/lib/rambling/trie/serializers.rb +11 -0
- data/lib/rambling/trie/serializers/file.rb +25 -0
- data/lib/rambling/trie/serializers/marshal.rb +38 -0
- data/lib/rambling/trie/serializers/yaml.rb +39 -0
- data/lib/rambling/trie/serializers/zip.rb +67 -0
- data/lib/rambling/trie/stringifyable.rb +20 -0
- data/lib/rambling/trie/version.rb +1 -1
- data/rambling-trie.gemspec +2 -2
- data/spec/integration/rambling/trie_spec.rb +45 -49
- data/spec/lib/rambling/trie/comparable_spec.rb +104 -0
- data/spec/lib/rambling/trie/compressed_node_spec.rb +44 -0
- data/spec/lib/rambling/trie/configuration/properties_spec.rb +49 -0
- data/spec/lib/rambling/trie/configuration/provider_collection_spec.rb +165 -0
- data/spec/lib/rambling/trie/container_spec.rb +127 -38
- data/spec/lib/rambling/trie/{inspector_spec.rb → inspectable_spec.rb} +7 -5
- data/spec/lib/rambling/trie/raw_node_spec.rb +22 -41
- data/spec/lib/rambling/trie/readers/plain_text_spec.rb +14 -0
- data/spec/lib/rambling/trie/serializers/file_spec.rb +11 -0
- data/spec/lib/rambling/trie/serializers/marshal_spec.rb +14 -0
- data/spec/lib/rambling/trie/serializers/yaml_spec.rb +14 -0
- data/spec/lib/rambling/trie/serializers/zip_spec.rb +30 -0
- data/spec/lib/rambling/trie/stringifyable_spec.rb +82 -0
- data/spec/lib/rambling/trie_spec.rb +120 -7
- data/spec/spec_helper.rb +7 -1
- data/spec/support/config.rb +5 -0
- data/spec/support/shared_examples/a_compressable_trie.rb +26 -0
- data/spec/support/shared_examples/a_serializable_trie.rb +26 -0
- data/spec/support/shared_examples/a_serializer.rb +29 -0
- data/spec/support/shared_examples/a_trie_data_structure.rb +29 -0
- data/spec/tmp/.gitkeep +0 -0
- metadata +51 -24
- data/lib/rambling/trie/compression.rb +0 -13
- data/lib/rambling/trie/inspector.rb +0 -11
- data/lib/rambling/trie/plain_text_reader.rb +0 -23
- data/lib/rambling/trie/tasks/gem.rb +0 -17
- data/lib/rambling/trie/tasks/helpers/path.rb +0 -17
- data/lib/rambling/trie/tasks/helpers/performance_report.rb +0 -17
- data/lib/rambling/trie/tasks/helpers/time.rb +0 -7
- data/lib/rambling/trie/tasks/performance.rb +0 -15
- data/lib/rambling/trie/tasks/performance/all.rb +0 -17
- data/lib/rambling/trie/tasks/performance/benchmark.rb +0 -201
- data/lib/rambling/trie/tasks/performance/directory.rb +0 -11
- data/lib/rambling/trie/tasks/performance/flamegraph.rb +0 -119
- data/lib/rambling/trie/tasks/performance/profile/call_tree.rb +0 -147
- data/lib/rambling/trie/tasks/performance/profile/memory.rb +0 -143
- data/spec/lib/rambling/trie/plain_text_reader_spec.rb +0 -18
@@ -1,147 +0,0 @@
|
|
1
|
-
namespace :performance do
|
2
|
-
namespace :profile do
|
3
|
-
include Helpers::Path
|
4
|
-
include Helpers::Time
|
5
|
-
|
6
|
-
def performance_report
|
7
|
-
@performance_report ||= PerformanceReport.new
|
8
|
-
end
|
9
|
-
|
10
|
-
def output
|
11
|
-
performance_report.output
|
12
|
-
end
|
13
|
-
|
14
|
-
class CallTreeProfile
|
15
|
-
def initialize dirname
|
16
|
-
@dirname = dirname
|
17
|
-
end
|
18
|
-
|
19
|
-
def perform times, params = nil
|
20
|
-
params = Array params
|
21
|
-
params << nil unless params.any?
|
22
|
-
|
23
|
-
result = RubyProf.profile merge_fibers: true do
|
24
|
-
params.each do |param|
|
25
|
-
times.times do
|
26
|
-
yield param
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
path = path 'reports', Rambling::Trie::VERSION, 'call-tree', time, dirname
|
32
|
-
FileUtils.mkdir_p path
|
33
|
-
printer = RubyProf::CallTreePrinter.new result
|
34
|
-
printer.print path: path
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
attr_reader :dirname
|
40
|
-
end
|
41
|
-
|
42
|
-
def generate_lookups_call_tree
|
43
|
-
output.puts 'Generating call tree profiling reports for lookups...'
|
44
|
-
|
45
|
-
words = %w(hi help beautiful impressionism anthropological)
|
46
|
-
|
47
|
-
trie = Rambling::Trie.create dictionary
|
48
|
-
compressed_trie = Rambling::Trie.create(dictionary).compress!
|
49
|
-
|
50
|
-
[ trie, compressed_trie ].each do |trie|
|
51
|
-
prefix = "profile-#{trie.compressed? ? 'compressed' : 'uncompressed'}"
|
52
|
-
|
53
|
-
call_tree_profile = CallTreeProfile.new "#{prefix}-word"
|
54
|
-
call_tree_profile.perform 200_000, words do
|
55
|
-
trie.word? word
|
56
|
-
end
|
57
|
-
|
58
|
-
call_tree_profile = CallTreeProfile.new "#{prefix}-partial-word"
|
59
|
-
call_tree_profile.perform 200_000, words do
|
60
|
-
trie.partial_word? word
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
output.puts 'Done'
|
65
|
-
end
|
66
|
-
|
67
|
-
def generate_scans_call_tree
|
68
|
-
output.puts 'Generating call tree profiling reports for scans...'
|
69
|
-
|
70
|
-
words = {
|
71
|
-
hi: 1_000,
|
72
|
-
help: 100_000,
|
73
|
-
beautiful: 100_000,
|
74
|
-
impressionism: 200_000,
|
75
|
-
anthropological: 200_000,
|
76
|
-
}
|
77
|
-
|
78
|
-
trie = Rambling::Trie.create dictionary
|
79
|
-
compressed_trie = Rambling::Trie.create(dictionary).compress!
|
80
|
-
|
81
|
-
[ trie, compressed_trie ].each do |trie|
|
82
|
-
dirname = "profile-#{trie.compressed? ? 'compressed' : 'uncompressed'}-scan"
|
83
|
-
call_tree_profile = CallTreeProfile.new dirname
|
84
|
-
|
85
|
-
words.each do |word, times|
|
86
|
-
call_tree_profile.perform times, word.to_s do |word|
|
87
|
-
trie.scan(word).size
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
output.puts 'Done'
|
93
|
-
end
|
94
|
-
|
95
|
-
namespace :call_tree do
|
96
|
-
desc 'Output banner'
|
97
|
-
task :banner do
|
98
|
-
performance_report.start 'Call Tree profile'
|
99
|
-
end
|
100
|
-
|
101
|
-
desc 'Generate call tree profiling reports for creation'
|
102
|
-
task creation: ['performance:directory', :banner] do
|
103
|
-
output.puts 'Generating call tree profiling reports for creation...'
|
104
|
-
|
105
|
-
call_tree_profile = CallTreeProfile.new 'profile-new-trie'
|
106
|
-
call_tree_profile.perform 5 do
|
107
|
-
trie = Rambling::Trie.create dictionary
|
108
|
-
end
|
109
|
-
|
110
|
-
output.puts 'Done'
|
111
|
-
end
|
112
|
-
|
113
|
-
desc 'Generate call tree profiling reports for compression'
|
114
|
-
task compression: ['performance:directory', :banner] do
|
115
|
-
output.puts 'Generating call tree profiling reports for compression...'
|
116
|
-
|
117
|
-
tries = []
|
118
|
-
5.times { tries << Rambling::Trie.create(dictionary) }
|
119
|
-
|
120
|
-
call_tree_profile = CallTreeProfile.new 'profile-compressed-trie'
|
121
|
-
call_tree_profile.perform 5, tries do |trie|
|
122
|
-
trie.compress!; nil
|
123
|
-
end
|
124
|
-
|
125
|
-
output.puts 'Done'
|
126
|
-
end
|
127
|
-
|
128
|
-
desc 'Generate call tree profiling reports for lookups'
|
129
|
-
task lookups: ['performance:directory', :banner] do
|
130
|
-
generate_lookups_call_tree
|
131
|
-
end
|
132
|
-
|
133
|
-
desc 'Generate call tree profiling reports for scans'
|
134
|
-
task scans: ['performance:directory', :banner] do
|
135
|
-
generate_scans_call_tree
|
136
|
-
end
|
137
|
-
|
138
|
-
desc 'Generate all call tree profiling reports'
|
139
|
-
task all: [
|
140
|
-
:creation,
|
141
|
-
:compression,
|
142
|
-
:lookups,
|
143
|
-
:scans,
|
144
|
-
]
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
@@ -1,143 +0,0 @@
|
|
1
|
-
namespace :performance do
|
2
|
-
namespace :profile do
|
3
|
-
include Helpers::Path
|
4
|
-
include Helpers::Time
|
5
|
-
|
6
|
-
def performance_report
|
7
|
-
@performance_report ||= PerformanceReport.new
|
8
|
-
end
|
9
|
-
|
10
|
-
def output
|
11
|
-
performance_report.output
|
12
|
-
end
|
13
|
-
|
14
|
-
class MemoryProfile
|
15
|
-
def initialize name
|
16
|
-
@name = name
|
17
|
-
end
|
18
|
-
|
19
|
-
def perform
|
20
|
-
result = MemoryProfiler.report allow_files: 'lib/rambling/trie', ignore_files: 'lib/rambling/trie/tasks' do
|
21
|
-
with_gc_stats do
|
22
|
-
yield
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
dir = path 'reports', Rambling::Trie::VERSION, 'memory', time
|
27
|
-
FileUtils.mkdir_p dir
|
28
|
-
result.pretty_print to_file: File.join(dir, name)
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
attr_reader :name
|
34
|
-
end
|
35
|
-
|
36
|
-
def with_gc_stats
|
37
|
-
output.puts "Live objects before - #{GC.stat[:heap_live_slots]}"
|
38
|
-
yield
|
39
|
-
output.puts "Live objects after - #{GC.stat[:heap_live_slots]}"
|
40
|
-
end
|
41
|
-
|
42
|
-
namespace :memory do
|
43
|
-
desc 'Output banner'
|
44
|
-
task :banner do
|
45
|
-
performance_report.start 'Memory profile'
|
46
|
-
end
|
47
|
-
|
48
|
-
desc 'Generate memory profiling reports for creation'
|
49
|
-
task creation: ['performance:directory', :banner] do
|
50
|
-
output.puts 'Generating memory profiling reports for creation...'
|
51
|
-
|
52
|
-
trie = nil
|
53
|
-
|
54
|
-
memory_profile = MemoryProfile.new 'memory-profile-new-trie'
|
55
|
-
memory_profile.perform do
|
56
|
-
trie = Rambling::Trie.create dictionary
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
desc 'Generate memory profiling reports for compression'
|
61
|
-
task compression: ['performance:directory', :banner] do
|
62
|
-
output.puts 'Generating memory profiling reports for compression...'
|
63
|
-
trie = Rambling::Trie.create dictionary
|
64
|
-
|
65
|
-
memory_profile = MemoryProfile.new 'memory-profile-trie-and-compress'
|
66
|
-
memory_profile.perform do
|
67
|
-
trie.compress!
|
68
|
-
end
|
69
|
-
|
70
|
-
with_gc_stats { GC.start }
|
71
|
-
end
|
72
|
-
|
73
|
-
desc 'Generate memory profiling reports for lookups'
|
74
|
-
task lookups: ['performance:directory', :banner] do
|
75
|
-
output.puts 'Generating memory profiling reports for lookups...'
|
76
|
-
|
77
|
-
words = %w(hi help beautiful impressionism anthropological)
|
78
|
-
|
79
|
-
trie = Rambling::Trie.create dictionary
|
80
|
-
compressed_trie = Rambling::Trie.create(dictionary).compress!
|
81
|
-
[ trie, compressed_trie ].each do |trie|
|
82
|
-
times = 10
|
83
|
-
|
84
|
-
prefix = "memory-profile-#{trie.compressed? ? 'compressed' : 'uncompressed'}-trie"
|
85
|
-
name = "#{prefix}-word"
|
86
|
-
memory_profile = MemoryProfile.new name
|
87
|
-
memory_profile.perform do
|
88
|
-
words.each do |word|
|
89
|
-
times.times do
|
90
|
-
trie.word? word
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
name = "#{prefix}-partial-word"
|
96
|
-
memory_profile = MemoryProfile.new name
|
97
|
-
memory_profile.perform do
|
98
|
-
words.each do |word|
|
99
|
-
times.times do
|
100
|
-
trie.partial_word? word
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
desc 'Generate memory profiling reports for scans'
|
108
|
-
task scans: ['performance:directory', :banner] do
|
109
|
-
output.puts 'Generating memory profiling reports for scans...'
|
110
|
-
|
111
|
-
words = {
|
112
|
-
hi: 1,
|
113
|
-
help: 100,
|
114
|
-
beautiful: 100,
|
115
|
-
impressionism: 200,
|
116
|
-
anthropological: 200,
|
117
|
-
}
|
118
|
-
|
119
|
-
trie = Rambling::Trie.create dictionary
|
120
|
-
compressed_trie = Rambling::Trie.create(dictionary).compress!
|
121
|
-
[ trie, compressed_trie ].each do |trie|
|
122
|
-
name = "memory-profile-#{trie.compressed? ? 'compressed' : 'uncompressed'}-trie-scan"
|
123
|
-
memory_profile = MemoryProfile.new name
|
124
|
-
memory_profile.perform do
|
125
|
-
words.each do |word, times|
|
126
|
-
times.times do
|
127
|
-
trie.scan(word.to_s).size
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
desc 'Generate all memory profiling reports'
|
135
|
-
task all: [
|
136
|
-
:creation,
|
137
|
-
:compression,
|
138
|
-
:lookups,
|
139
|
-
:scans,
|
140
|
-
]
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Rambling
|
4
|
-
module Trie
|
5
|
-
describe PlainTextReader do
|
6
|
-
describe '#each_word' do
|
7
|
-
let(:filepath) { File.join(::SPEC_ROOT, 'assets', 'test_words.en_US.txt') }
|
8
|
-
let(:words) { File.readlines(filepath).map &:chomp }
|
9
|
-
|
10
|
-
it 'yields every word yielded by the file' do
|
11
|
-
yielded_words = []
|
12
|
-
subject.each_word(filepath) { |word| yielded_words << word }
|
13
|
-
expect(yielded_words).to eq words
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|