diff --git a/dev/performance/bench_excel_writers.py b/dev/performance/bench_excel_writers.py index 47139602..7ddecfe3 100644 --- a/dev/performance/bench_excel_writers.py +++ b/dev/performance/bench_excel_writers.py @@ -29,15 +29,15 @@ def print_elapsed_time(module_name, elapsed): - """ Print module run times in a consistent format. """ + """Print module run times in a consistent format.""" print(f" {module_name:28s}: {elapsed:6.2f}") def time_xlsxwriter(): - """ Run XlsxWriter in default mode. """ + """Run XlsxWriter in default mode.""" start_time = perf_counter() - workbook = xlsxwriter.Workbook('xlsxwriter.xlsx') + workbook = xlsxwriter.Workbook("xlsxwriter.xlsx") worksheet = workbook.add_worksheet() for row in range(row_max // 2): @@ -49,15 +49,14 @@ def time_xlsxwriter(): workbook.close() elapsed = perf_counter() - start_time - print_elapsed_time('xlsxwriter', elapsed) + print_elapsed_time("xlsxwriter", elapsed) def time_xlsxwriter_optimised(): - """ Run XlsxWriter in optimised/constant memory mode. """ + """Run XlsxWriter in optimised/constant memory mode.""" start_time = perf_counter() - workbook = xlsxwriter.Workbook('xlsxwriter_opt.xlsx', - {'constant_memory': True}) + workbook = xlsxwriter.Workbook("xlsxwriter_opt.xlsx", {"constant_memory": True}) worksheet = workbook.add_worksheet() for row in range(row_max // 2): @@ -69,11 +68,11 @@ def time_xlsxwriter_optimised(): workbook.close() elapsed = perf_counter() - start_time - print_elapsed_time('xlsxwriter (constant_memory)', elapsed) + print_elapsed_time("xlsxwriter (constant_memory)", elapsed) def time_openpyxl(): - """ Run OpenPyXL in default mode. """ + """Run OpenPyXL in default mode.""" start_time = perf_counter() workbook = openpyxl.workbook.Workbook() @@ -85,14 +84,14 @@ def time_openpyxl(): for col in range(col_max): worksheet.cell(row * 2 + 2, col + 1, row + col) - workbook.save('openpyxl.xlsx') + workbook.save("openpyxl.xlsx") elapsed = perf_counter() - start_time - print_elapsed_time('openpyxl', elapsed) + print_elapsed_time("openpyxl", elapsed) def time_openpyxl_optimised(): - """ Run OpenPyXL in optimised mode. """ + """Run OpenPyXL in optimised mode.""" start_time = perf_counter() workbook = openpyxl.workbook.Workbook(write_only=True) @@ -105,18 +104,18 @@ def time_openpyxl_optimised(): num_data = [row + col for col in range(col_max)] worksheet.append(num_data) - workbook.save('openpyxl_opt.xlsx') + workbook.save("openpyxl_opt.xlsx") elapsed = perf_counter() - start_time - print_elapsed_time('openpyxl (optimised)', elapsed) + print_elapsed_time("openpyxl (optimised)", elapsed) def time_pyexcelerate(): - """ Run pyexcelerate in "faster" mode. """ + """Run pyexcelerate in "faster" mode.""" start_time = perf_counter() workbook = pyexcelerate.Workbook() - worksheet = workbook.new_sheet('Sheet1') + worksheet = workbook.new_sheet("Sheet1") for row in range(row_max // 2): for col in range(col_max): @@ -124,18 +123,18 @@ def time_pyexcelerate(): for col in range(col_max): worksheet.set_cell_value(row * 2 + 2, col + 1, row + col) - workbook.save('pyexcelerate.xlsx') + workbook.save("pyexcelerate.xlsx") elapsed = perf_counter() - start_time - print_elapsed_time('pyexcelerate', elapsed) + print_elapsed_time("pyexcelerate", elapsed) def time_xlwt(): - """ Run xlwt in default mode. """ + """Run xlwt in default mode.""" start_time = perf_counter() workbook = xlwt.Workbook() - worksheet = workbook.add_sheet('Sheet1') + worksheet = workbook.add_sheet("Sheet1") for row in range(row_max // 2): for col in range(col_max): @@ -143,10 +142,10 @@ def time_xlwt(): for col in range(col_max): worksheet.write(row * 2 + 1, col, row + col) - workbook.save('xlwt.xls') + workbook.save("xlwt.xls") elapsed = perf_counter() - start_time - print_elapsed_time('xlwt', elapsed) + print_elapsed_time("xlwt", elapsed) print("") diff --git a/dev/performance/perf3.py b/dev/performance/perf3.py index 1570ce82..8047b732 100644 --- a/dev/performance/perf3.py +++ b/dev/performance/perf3.py @@ -8,6 +8,7 @@ # import os import sys + try: from time import process_time except ImportError: @@ -33,24 +34,23 @@ def print_elapsed_time(module_name, elapsed, optimised=False): - """ Print module run times in a consistent format. """ + """Print module run times in a consistent format.""" if optimised: module_name += " (optimised)" print(f" {module_name:22s}: {elapsed:6.2f}") def time_xlsxwriter(optimised=False): - """ Run XlsxWriter in optimised/constant memory mode. """ + """Run XlsxWriter in optimised/constant memory mode.""" options = {} module_name = "xlsxwriter" if optimised: - options['constant_memory'] = True + options["constant_memory"] = True start_time = process_time() - filename = 'xlsxwriter_opt.xlsx' + filename = "xlsxwriter_opt.xlsx" - workbook = xlsxwriter.Workbook(filename, - options=options) + workbook = xlsxwriter.Workbook(filename, options=options) for r in range(sheets): worksheet = workbook.add_worksheet() @@ -69,11 +69,11 @@ def time_xlsxwriter(optimised=False): def time_openpyxl(optimised=False): - """ Run OpenPyXL in default mode. """ + """Run OpenPyXL in default mode.""" module_name = "openpyxl" start_time = process_time() - filename = 'openpyxl.xlsx' + filename = "openpyxl.xlsx" workbook = openpyxl.Workbook(write_only=optimised) for r in range(sheets): @@ -113,4 +113,3 @@ def time_openpyxl(optimised=False): time_openpyxl() time_openpyxl(optimised=True) print("") - diff --git a/dev/performance/perf_pyx.py b/dev/performance/perf_pyx.py index d56f4eff..f3a64a0d 100644 --- a/dev/performance/perf_pyx.py +++ b/dev/performance/perf_pyx.py @@ -35,8 +35,7 @@ start_time = perf_counter() # Start of program being tested. -workbook = xlsxwriter.Workbook('py_ewx.xlsx', - {'constant_memory': optimise}) +workbook = xlsxwriter.Workbook("py_ewx.xlsx", {"constant_memory": optimise}) worksheet = workbook.add_worksheet() worksheet.set_column(0, col_max, 18) @@ -60,4 +59,4 @@ # Print a simple CSV output for reporting. -print(f"{row_max * 2:6d}, {col_max:3d}, {elapsed:6.2f}, {total_size}") \ No newline at end of file +print(f"{row_max * 2:6d}, {col_max:3d}, {elapsed:6.2f}, {total_size}")