diff options
| author | mo khan <mo.khan@gmail.com> | 2020-05-10 21:18:26 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-05-10 21:21:05 -0600 |
| commit | 727e48b57c8c1ca14240fdb425b4d3654a7b00e7 (patch) | |
| tree | 524c7ad853100b92897c048a46425547a4b0510a /spec/integration/core | |
| parent | c19558661b919522950a8f3f8006fd647f18de22 (diff) | |
Optimize processing of index file
Diffstat (limited to 'spec/integration/core')
| -rw-r--r-- | spec/integration/core/cache_spec.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/spec/integration/core/cache_spec.rb b/spec/integration/core/cache_spec.rb index 3eb9de3..a982fde 100644 --- a/spec/integration/core/cache_spec.rb +++ b/spec/integration/core/cache_spec.rb @@ -111,7 +111,7 @@ RSpec.describe Spandx::Core::Cache do it 'builds an index that contains the seek position for the start of each line' do data_file = subject.datafile_for('spandx') data_file.open_file do |io| - data_file.index.each do |position| + data_file.index.data.each do |position| unless position.zero? io.seek(position - 1) expect(io.readchar).to eql("\n") @@ -161,6 +161,24 @@ RSpec.describe Spandx::Core::Cache do it 'yields each item quickly' do expect { subject.take(100_000).count }.to perform_under(0.1).sample(10) end + + xit 'profiles each option' do + datafile = Spandx::Core::DataFile.new('~/.local/share/spandx/rubygems-cache/.index/02/rubygems') + Benchmark.ips do |x| + x.report('fastest-csv') { FastestCSV.foreach(datafile.absolute_path) { |y| } } + x.report('manual-gets') do + datafile.open_file(mode: 'rb') do |io| + while (x = io.gets) + ::CsvParser.parse_line(x) + end + end + end + x.report('manual-eof') { datafile.open_file { |io| FastestCSV.parse_line(io.readline) until io.eof? } } + x.report('manual-exception') { datafile.open_file { |io| loop { FastestCSV.parse_line(io.readline) } } } + + x.compare! + end + end end end end |
