From 384079ad73fd52c4353c4008779868db386b82b7 Mon Sep 17 00:00:00 2001 From: Thomas Lindner Date: Fri, 30 Dec 2022 16:55:19 +0100 Subject: [PATCH] better profiling --- src/blunderboard/__init__.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/blunderboard/__init__.py b/src/blunderboard/__init__.py index 908baac..6a70a10 100644 --- a/src/blunderboard/__init__.py +++ b/src/blunderboard/__init__.py @@ -1,20 +1,24 @@ from blunderboard.blunderevaluator import BlunderEvaluator from blunderboard.boardreader import BoardReader from blunderboard.movegenerator import MoveGenerator -from time import sleep import cProfile +from pstats import SortKey +from time import sleep def main_content(): - blunder_evaluator = BlunderEvaluator() - move_generator = MoveGenerator(blunder_evaluator) - reader = BoardReader(move_generator) - reader.scan() - reader.print() - while True: + try: + blunder_evaluator = BlunderEvaluator() + move_generator = MoveGenerator(blunder_evaluator) + reader = BoardReader(move_generator) reader.scan() - sleep(0.1) + reader.print() + while True: + reader.scan() + sleep(0.1) + except KeyboardInterrupt: + pass def main(): - cProfile.runctx("main_content()", globals(), locals(), filename=__file__) + cProfile.runctx("main_content()", globals(), locals(), sort=SortKey.CUMULATIVE)