Created
October 14, 2020 16:07
-
-
Save pythonandchips/a676ff28a1349a4ae7f2e30993c0aa52 to your computer and use it in GitHub Desktop.
Benchmark exporting data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
require "perform_on_replica" | |
company = Company.find(126455) | |
class BenchmarkExporter | |
include PerformOnReplica | |
def initialize(company) | |
@company = company | |
@exportable_data_types = [ | |
Exporter::ExportableData::AllCompanyData::BankAccountEntries, | |
# Exporter::ExportableData::AllCompanyData::Contacts, | |
] | |
end | |
def benchmark | |
perform_on_replica do | |
results = [] | |
exportable_data = @exportable_data_types.map { |data| data.new(@company) } | |
exportable_data.each do |data| | |
result = Benchmark.measure { | |
writer = Exporter::Writers::Excel.new("/dev/null") | |
coordinator = Exporter::Coordinator.new(Array(data), writer) | |
coordinator.run | |
} | |
results << "Benchmarking #{data.class.name} for company #{@company.id} \nresults: #{result}\n\n" | |
end | |
results.each{|r| puts r } | |
nil | |
end | |
end | |
end | |
# company =Company.find_by(subdomain: "fac") | |
# BenchmarkExporter.new(company).benchmark; nil | |
__END__ | |
Small company | |
Benchmarking Exporter::ExportableData::AllCompanyData::BankAccountEntries for company 342493 no of records 1043 | |
results: 1.111476 0.040519 1.151995 ( 5.933205) | |
Benchmarking Exporter::ExportableData::AllCompanyData::Contacts for company 342493 no of records 4 | |
results: 0.016248 0.001244 0.017492 ( 3.424007) | |
Large company | |
Benchmarking Exporter::ExportableData::AllCompanyData::BankAccountEntries for company 126455, no of records 305644 | |
results: 346.779138 7.157765 353.936903 (855.612951) | |
Benchmarking Exporter::ExportableData::AllCompanyData::Contacts for company 126455, no of records 192546 | |
results: 377.754049 15.727033 393.481082 (706.528100) | |
Optimised query | |
Benchmarking Exporter::ExportableData::AllCompanyData::BankAccountEntries for company 126455, no of records 305644 | |
results: 193.753383 0.423825 194.177208 (453.740573) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment