Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pixelblend/a95a9d0dcbaf0d3bbb86c78059b0681b to your computer and use it in GitHub Desktop.
Save pixelblend/a95a9d0dcbaf0d3bbb86c78059b0681b to your computer and use it in GitHub Desktop.
Benchmark exporting data
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::BankAccounts,
Exporter::ExportableData::AllCompanyData::BankAccountEntries,
Exporter::ExportableData::AllCompanyData::BankAccountTransactions,
Exporter::ExportableData::AllCompanyData::Payslips,
Exporter::ExportableData::AllCompanyData::Contacts,
Exporter::ExportableData::AllCompanyData::Projects,
Exporter::ExportableData::AllCompanyData::Invoices,
Exporter::ExportableData::AllCompanyData::Estimates,
Exporter::ExportableData::AllCompanyData::Bills,
Exporter::ExportableData::AllCompanyData::Expenses,
Exporter::ExportableData::AllCompanyData::Tasks,
Exporter::ExportableData::AllCompanyData::Timeslips,
Exporter::ExportableData::AllCompanyData::VatReturns,
Exporter::ExportableData::AllCompanyData::RecurringInvoiceProfiles,
Exporter::ExportableData::AllCompanyData::CapitalAssets,
Exporter::ExportableData::AllCompanyData::Companies,
Exporter::ExportableData::AllCompanyData::CustomEmailDomains,
Exporter::ExportableData::AllCompanyData::EmailTemplates,
Exporter::ExportableData::AllCompanyData::GocardlessPreauthAgreements,
Exporter::ExportableData::AllCompanyData::LoginAttempts,
Exporter::ExportableData::AllCompanyData::JournalEntries,
Exporter::ExportableData::AllCompanyData::OpeningBalances,
Exporter::ExportableData::AllCompanyData::PriceListItems,
Exporter::ExportableData::AllCompanyData::SenderEmailAddresses,
Exporter::ExportableData::AllCompanyData::StockItems,
Exporter::ExportableData::AllCompanyData::Themes,
Exporter::ExportableData::AllCompanyData::Users,
Exporter::ExportableData::AllCompanyData::YearEndApprovals,
]
end
def benchmark
results = []
perform_on_replica do
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)
@pythonandchips
Copy link

Full run against company 126455

Benchmarking Exporter::ExportableData::AllCompanyData::BankAccounts for company 126455
results: 0.011018 0.004755 0.015773 ( 0.017244)

Benchmarking Exporter::ExportableData::AllCompanyData::BankAccountEntries for company 126455
results: 201.060840 0.656588 201.717428 (497.032056)

Benchmarking Exporter::ExportableData::AllCompanyData::BankAccountTransactions for company 126455
results: 4.782232 0.018096 4.800328 ( 6.568402)

Benchmarking Exporter::ExportableData::AllCompanyData::Payslips for company 126455
results: 0.080093 0.000833 0.080926 ( 0.122373)

Benchmarking Exporter::ExportableData::AllCompanyData::Contacts for company 126455
results: 64.416742 0.236603 64.653345 (106.473763)

Benchmarking Exporter::ExportableData::AllCompanyData::Projects for company 126455
results: 0.009764 0.000496 0.010260 ( 1.403496)

Benchmarking Exporter::ExportableData::AllCompanyData::Invoices for company 126455
results: 1895.051930 49.950440 1945.002370 (2693.970076)

Benchmarking Exporter::ExportableData::AllCompanyData::Estimates for company 126455
results: 0.023192 0.000386 0.023578 ( 1.213516)

Benchmarking Exporter::ExportableData::AllCompanyData::Bills for company 126455
results: 0.102895 0.002763 0.105658 ( 0.166929)

Benchmarking Exporter::ExportableData::AllCompanyData::Expenses for company 126455
results: 0.047734 0.001312 0.049046 ( 0.091662)

Benchmarking Exporter::ExportableData::AllCompanyData::Tasks for company 126455
results: 0.009568 0.000278 0.009846 ( 0.797679)

Benchmarking Exporter::ExportableData::AllCompanyData::Timeslips for company 126455
results: 0.004927 0.000114 0.005041 ( 0.006719)

Benchmarking Exporter::ExportableData::AllCompanyData::VatReturns for company 126455
results: 0.052868 0.000619 0.053487 ( 0.390161)

Benchmarking Exporter::ExportableData::AllCompanyData::RecurringInvoiceProfiles for company 126455
results: 0.019600 0.000729 0.020329 ( 20.183205)

Benchmarking Exporter::ExportableData::AllCompanyData::CapitalAssets for company 126455
results: 0.039533 0.000095 0.039628 ( 0.039979)

Benchmarking Exporter::ExportableData::AllCompanyData::Companies for company 126455
results: 0.006255 0.000492 0.006747 ( 0.007114)

Benchmarking Exporter::ExportableData::AllCompanyData::CustomEmailDomains for company 126455
results: 0.002785 0.000071 0.002856 ( 0.005269)

Benchmarking Exporter::ExportableData::AllCompanyData::EmailTemplates for company 126455
results: 0.036919 0.000088 0.037007 ( 0.039277)

Benchmarking Exporter::ExportableData::AllCompanyData::GocardlessPreauthAgreements for company 126455
results: 0.002680 0.000325 0.003005 ( 0.003538)

Benchmarking Exporter::ExportableData::AllCompanyData::LoginAttempts for company 126455
results: 0.056690 0.000696 0.057386 ( 0.064657)

Benchmarking Exporter::ExportableData::AllCompanyData::JournalEntries for company 126455
results: 0.060244 0.001406 0.061650 ( 0.075672)

Benchmarking Exporter::ExportableData::AllCompanyData::OpeningBalances for company 126455
results: 0.040916 0.001342 0.042258 ( 0.053047)

Benchmarking Exporter::ExportableData::AllCompanyData::PriceListItems for company 126455
results: 0.003520 0.000069 0.003589 ( 0.005945)

Benchmarking Exporter::ExportableData::AllCompanyData::SenderEmailAddresses for company 126455
results: 0.004513 0.000092 0.004605 ( 0.009690)

Benchmarking Exporter::ExportableData::AllCompanyData::StockItems for company 126455
results: 0.001879 0.000042 0.001921 ( 0.002051)

Benchmarking Exporter::ExportableData::AllCompanyData::Themes for company 126455
results: 0.003033 0.000069 0.003102 ( 0.005335)

Benchmarking Exporter::ExportableData::AllCompanyData::Users for company 126455
results: 0.004842 0.000230 0.005072 ( 0.005430)

Benchmarking Exporter::ExportableData::AllCompanyData::YearEndApprovals for company 126455
results: 0.002579 0.000438 0.003017 ( 0.004492)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment