From 3c41f6b0f8cc5062e5b703bbbacee4bb73c13f79 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sat, 20 Nov 2021 14:05:53 +0100 Subject: [PATCH] #1153 draw.py timing --- src/ifcopenshell-python/ifcopenshell/draw.py | 25 +++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/draw.py b/src/ifcopenshell-python/ifcopenshell/draw.py index 0adeb8ab89..9e19820ffa 100644 --- a/src/ifcopenshell-python/ifcopenshell/draw.py +++ b/src/ifcopenshell-python/ifcopenshell/draw.py @@ -312,7 +312,20 @@ def main(settings, files, iterators=None, merge_projection=True, progress_functi if __name__ == "__main__": import sys + import time import argparse + + times = [] + + def measure(task, fn): + t0 = time.time() + r = fn() + dt = time.time() - t0 + times.append((task, dt)) + return r + + def print_progress(*args): + print("\r", *args, " "*10, end="", flush=True) parser = argparse.ArgumentParser() @@ -339,6 +352,12 @@ if __name__ == "__main__": settings = draw_settings(**args) - files = list(map(ifcopenshell.open, files)) - open(output, "wb").write(main(settings, files, progress_function=lambda *args: print("\r", *args, " "*10, end="", flush=True))) - print("\r Done!", " " * 10) + files = measure("open files", lambda: list(map(ifcopenshell.open, files))) + result = measure("processing", lambda: main(settings, files, progress_function=print_progress)) + open(output, "wb").write(result) + + print("\r Done!", " " * 20) + + for t, dt in times: + print(f"{t}: {dt}") +