Source code for wolframclient.utils.debug

# -*- coding: utf-8 -*-

from __future__ import absolute_import, print_function, unicode_literals

from decimal import Decimal
from functools import wraps

from wolframclient.utils.api import time


[docs]def timed(function): def inner(*args, **opts): t = time.perf_counter() value = function(*args, **opts) return time.perf_counter() - t, value return inner
[docs]def echo(x): print(x) return x
[docs]def timed_repeated(N=30): def repeated(function): def inner(*args, **opts): return repeated_timing(function, *args, N=N, **opts) return inner return repeated
[docs]def repeated_timing(function, *args, **opts): N = opts.pop("N", 30) timed_func = timed(function) timers = [] for _ in range(N): timer, res = timed_func(*args, **opts) timers.append(timer) timers = sorted(timers) min = int(0.1 * N) max = int(0.9 * N) trimmed_timers = timers[min:max] return sum(trimmed_timers) / len(trimmed_timers), res