Skip to content

Commit

Permalink
Actually measure performance of the program
Browse files Browse the repository at this point in the history
  • Loading branch information
skalee committed Mar 14, 2021
1 parent 734b0a7 commit f0dc56e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
14 changes: 8 additions & 6 deletions lib/iev/termbase/cli/command_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ module CommandHelper
protected

def save_collection_to_files(collection, output_dir)
info "Writing concepts to files..."
output_dir = Pathname.new(output_dir.to_s)
Profiler.measure("writing-yamls") do
info "Writing concepts to files..."
output_dir = Pathname.new(output_dir.to_s)

concept_dir = output_dir.join("concepts")
FileUtils.mkdir_p(concept_dir)
concept_dir = output_dir.join("concepts")
FileUtils.mkdir_p(concept_dir)

collection.each do |key, concept|
concept.to_file(concept_dir.join("concept-#{key}.yaml"))
collection.each do |key, concept|
concept.to_file(concept_dir.join("concept-#{key}.yaml"))
end
end
end

Expand Down
10 changes: 6 additions & 4 deletions lib/iev/termbase/concept_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ def add_term(term)
end

def self.build_from_dataset(ds)
new.tap do |concept_collection|
ds.each do |row|
term = TermBuilder.build_from(row)
concept_collection.add_term(term)
Profiler.measure("building-collection") do
new.tap do |concept_collection|
ds.each do |row|
term = TermBuilder.build_from(row)
concept_collection.add_term(term)
end
end
end
end
Expand Down
24 changes: 13 additions & 11 deletions lib/iev/termbase/db_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ def initialize(db)
end

def import_spreadsheet(file)
workbook = open_workbook(file)
row_enumerator = workbook.sheets.first.simple_rows.each
Profiler.measure("xlsx-import") do
workbook = open_workbook(file)
row_enumerator = workbook.sheets.first.simple_rows.each

title_row = row_enumerator.next
symbolized_title_row = title_row.compact.transform_values(&:to_sym)
title_row = row_enumerator.next
symbolized_title_row = title_row.compact.transform_values(&:to_sym)

create_table(symbolized_title_row.values)
create_table(symbolized_title_row.values)

loop do
row = row_enumerator.next
next if row.empty?
data = prepare_data(row, symbolized_title_row)
display_progress(data)
insert_data(data)
loop do
row = row_enumerator.next
next if row.empty?
data = prepare_data(row, symbolized_title_row)
display_progress(data)
insert_data(data)
end
end
end

Expand Down

0 comments on commit f0dc56e

Please sign in to comment.