From 0837132ce30503c90915df6b6a8bbcefd1b8b714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Sun, 12 Feb 2017 12:25:43 +0100 Subject: [PATCH] Make the benchmarking script Python 2 compatible Ended up using `time.time()`, even if it supposedly has worse accuracy, because Python running under WSL supports `time.clock()` very badly. --- scripts/benchmarkCompile.py | 39 +++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/scripts/benchmarkCompile.py b/scripts/benchmarkCompile.py index 26df15b5..6f647511 100755 --- a/scripts/benchmarkCompile.py +++ b/scripts/benchmarkCompile.py @@ -1,8 +1,17 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python + +from __future__ import print_function import time, subprocess, sys, os, shutil, glob, random import argparse -from statistics import median, stdev + +def median(lst): + lst = sorted(lst) + mid, odd = divmod(len(lst), 2) + if odd: + return lst[mid] + else: + return (lst[mid - 1] + lst[mid]) / 2.0 compiler_path = '' @@ -40,23 +49,23 @@ def create_catch_main(): f.write(main_file) def compile_main(): - start_t = time.perf_counter() + start_t = time.time() subprocess.check_call([compiler_path, main_name, '-c']) - end_t = time.perf_counter() + end_t = time.time() return end_t - start_t def compile_files(): cpp_files = glob.glob('*.cpp') - start_t = time.perf_counter() + start_t = time.time() subprocess.check_call([compiler_path] + cpp_files + ['-c']) - end_t = time.perf_counter() + end_t = time.time() return end_t - start_t def link_files(): obj_files = glob.glob('*.o') - start_t = time.perf_counter() + start_t = time.time() subprocess.check_call([compiler_path] + obj_files) - end_t = time.perf_counter() + end_t = time.time() return end_t - start_t def benchmark(func): @@ -101,20 +110,20 @@ parser.add_argument('-I', '--catch-header', default='catch.hpp', help = 'Path to parser.add_argument('-c', '--compiler', default='g++', help = 'Compiler to use, default: g++') # Allow creating files only, without running the whole thing -parser.add_argument('-g', '--generate-only', action='store_true', help='Generate test files and quit') +parser.add_argument('-g', '--generate-files', action='store_true', help='Generate test files and quit') args = parser.parse_args() compiler_path = args.compiler catch_path = args.catch_header -create_temp_dir() -copy_catch(catch_path) os.chdir(dir_name) -# now create the fake test files -generate_files() -# Early exit -if args.generate_only: +if args.generate_files: + create_temp_dir() + copy_catch(catch_path) + # now create the fake test files + generate_files() + # Early exit print('Finished generating files') exit(1)