def main(): args = [a for a in sys.argv[1:] if not a.startswith("-")] opts = [o for o in sys.argv[1:] if o.startswith("-")] if "-h" in opts or "--help" in opts: print(__doc__) return script_to_run = args[0] notif = opts[0][1:] starttime = time.time() call(["python", script_to_run, notif]) endtime = time.time() diff = endtime - starttime nodifly_key, nodifly_secret = load_keys() alert_type(starttime=starttime, endtime=endtime, duration=str(_format_time(diff)), from_where='terminal', kind=notif, alias=script_to_run, key=nodifly_key, secret=nodifly_secret) path = check_system() filename = path + "nodoutput123ez.csv" if os.path.exists(filename): os.remove(filename)
def post_run_cell(self): # show the elapsed time if self.start_time: diff = time.time() - self.start_time print('time: %s' % _format_time(diff)) # alert finish if more than 30 seconds if diff > 30: alert() self.start_time = None
def post_run_cell(self): # show the elapsed time if self.start_time: diff = time.time() - self.start_time print('time: %s' % _format_time(diff)) # alert finish if more than 30 seconds if diff > 30: alert() self.start_time = None
def post_run_cell(self): if self.start_time: end_time = time.time() diff = end_time - self.start_time print('\033[1m' + 'Nodifly: nodifly.com' + '\033[0m') print('\033[1m' + 'Finished at: ' + '\033[0m' + str( time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(self.start_time)))) print('\033[1m' + 'Duration: ' + '\033[0m' + str(_format_time(diff))) alert_type(starttime=self.start_time, endtime=end_time, duration=str(_format_time(diff)), kind=self.kind, alias=self.alias, from_where='jupyter', key=self.key, secret=self.secret) self.start_time = None path = check_system() filename = path + "nodoutput123ez.csv" if os.path.exists(filename): os.remove(filename)
def timeit2(self, line='', cell=None): import timeit opts, stmt = self.parse_options(line, 'n:r:gtcp:', posix=False, strict=False) if stmt == "" and cell is None: return timefunc = timeit.default_timer number = int(getattr(opts, "n", 0)) repeat = int(getattr(opts, "r", timeit.default_repeat)) precision = int(getattr(opts, "p", 3)) if hasattr(opts, "t"): timefunc = time.time if hasattr(opts, "c"): timefunc = clock if hasattr(opts, "g"): timer = timeit.Timer(timer=timefunc, setup='gc.enable()') else: timer = timeit.Timer(timer=timefunc) # this code has tight coupling to the inner workings of timeit.Timer, # but is there a better way to achieve that the code stmt has access # to the shell namespace? transform = self.shell.input_splitter.transform_cell if cell is None: # called as line magic ast_setup = ast.parse("pass") ast_stmt = ast.parse(transform(stmt)) else: ast_setup = ast.parse(transform(stmt)) ast_stmt = ast.parse(transform(cell)) ast_setup = self.shell.transform_ast(ast_setup) ast_stmt = self.shell.transform_ast(ast_stmt) # This codestring is taken from timeit.template - we fill it in as an # AST, so that we can apply our AST transformations to the user code # without affecting the timing code. timeit_ast_template = ast.parse('def inner(_it, _timer):\n' ' setup\n' ' _t0 = _timer()\n' ' for _i in _it:\n' ' stmt\n' ' _t1 = _timer()\n' ' return _t1 - _t0\n') class TimeitTemplateFiller(ast.NodeTransformer): "This is quite tightly tied to the template definition above." def visit_FunctionDef(self, node): "Fill in the setup statement" self.generic_visit(node) if node.name == "inner": node.body[:1] = ast_setup.body return node def visit_For(self, node): "Fill in the statement to be timed" if getattr(getattr(node.body[0], 'value', None), 'id', None) == 'stmt': node.body = ast_stmt.body return node timeit_ast = TimeitTemplateFiller().visit(timeit_ast_template) timeit_ast = ast.fix_missing_locations(timeit_ast) # Track compilation time so it can be reported if too long # Minimum time above which compilation time will be reported tc_min = 0.1 t0 = clock() code = compile(timeit_ast, "<magic-timeit>", "exec") tc = clock() - t0 ns = {} exec code in self.shell.user_ns, ns timer.inner = ns["inner"] if number == 0: # determine number so that 0.2 <= total time < 2.0 number = 1 for i in range(1, 10): if timer.timeit(number) >= 0.2: break number *= 10 result = timer.repeat(repeat, number) best = min(result) / number worst = max(result) / number avg = sum(result) / number / float(len(result)) print u"{0} loops" \ u"\n AVG of {1}: {2:>5} per loop" \ u"\n BEST of {1}: {3:>5} per loop" \ u"\n WORST of {1}: {4:>5} per loop".format( number, repeat, _format_time(avg, precision), _format_time(best, precision), _format_time(worst, precision) ) if tc > tc_min: print "Compiler time: %.2f s" % tc
post_edge_prob_list.append(post_edge_prob + tmp / (min_iter - k + 1)) meeting_time_list.append(meeting_time) return post_edge_prob_list, meeting_time_list, result_list S = 8 # The number of CPU cores used tmp_seed = cpmcmc.random_seed(rng) start_time = time.perf_counter() print("Starting computation with", n_hours, "hour time limit at", time.asctime(time.gmtime()), "UTC") result_list = p_tqdm.p_umap(post_edge_prob_fun, range(S)) print("Elapsed time:", IPy_exec._format_time(time.perf_counter() - start_time)) meeting_time = [] for s in range(S): for i in range(len(result_list[s][0])): meeting_time.append(result_list[s][1][i]) if len(meeting_time) > 0: print("Median:", np.median(meeting_time)) print("Max:", np.max(meeting_time)) post_edge_prob = np.empty((len(meeting_time), p, p)) ind = 0 for s in range(S): for i in range(len(result_list[s][0])):
def print_time(self, dt, label): ts = _format_time(dt) msg = "%8s" % ts if label: msg = "%s: %s" % (label, msg) print ('%s%s' % (' ' * len(self.tics), msg))