From 270e48158e3fec151c4be8bbacab483393fcc5e1 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Tue, 5 Jan 2016 18:07:53 +0100 Subject: monkey.edits: cache test results --- monkey/edits.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'monkey') diff --git a/monkey/edits.py b/monkey/edits.py index f087074..829fcb6 100644 --- a/monkey/edits.py +++ b/monkey/edits.py @@ -207,6 +207,11 @@ if __name__ == '__main__': ] edits, submissions, queries = {}, {}, {} + try: + test_results = pickle.load(open('test_results.pickle', 'rb')) + except: + test_results = collections.defaultdict(dict) + for problem in Problem.list(): pid = problem.id solutions = [s for s in Solution.filter(problem_id=pid, done=True) @@ -226,8 +231,15 @@ if __name__ == '__main__': dependencies = sorted([p[2:] for p in other_problems if p.identifier in used_predicate_identifiers]) + # Check for cached results. + normal_code = stringify(rename_vars(tokenize(code))) + code_key = (normal_code, tuple(dependencies)) + if code_key in test_results[pid]: + return test_results[pid][code_key] + aux_code = '\n' + solutions_for_problems('prolog', dependencies) + '\n' + facts correct, hints = problem_module.test(code, aux_code) + test_results[pid][code_key] = correct return correct print('Analyzing traces for {}… '.format(problem.identifier), end='', flush=True) @@ -241,3 +253,4 @@ if __name__ == '__main__': traceback.print_exc() pickle.dump((edits, submissions, queries), open('edits.pickle', 'wb')) + pickle.dump(test_results, open('test_results.pickle', 'wb')) -- cgit v1.2.1