Skip to content

Instantly share code, notes, and snippets.

@pythonandchips
Created October 14, 2020 16:07
Show Gist options
  • Save pythonandchips/a676ff28a1349a4ae7f2e30993c0aa52 to your computer and use it in GitHub Desktop.
Save pythonandchips/a676ff28a1349a4ae7f2e30993c0aa52 to your computer and use it in GitHub Desktop.

Revisions

  1. pythonandchips created this gist Oct 14, 2020.
    63 changes: 63 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    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)