<commit_before>import time

TIMY = 'Timy'

class Timer(object):

    def __init__(self, ident=TIMY):
        self.ident = ident
        self.start = 0

    def __enter__(self):
        self.start = time.time()
        return self

    def __exit__(self, type, value, traceback):
        self.show('{:f}'.format(self.elapsed))

    @property
    def elapsed(self):
        return time.time() - self.start

    def track(self, name='track'):
        self.show('({}) {:f}'.format(name, self.elapsed))

    def show(self, text):
        print('{} {} seconds'.format(self.ident, text))


def timer(ident=TIMY, loops=1):
    def _timer(function, *args, **kwargs):
        def wrapper(*args, **kwargs):
            times = []
            for _ in range(loops):
                start = time.time()
                result = function(*args, **kwargs)
                end = time.time()
                times.append(end - start)

            print('{} executed ({}) for {} time(s) in {:f} seconds'.format(
                ident, function.__name__, loops, sum(times)))
            print('{} best time was {:f} seconds'.format(ident, min(times)))
            return result
        return wrapper
    return _timer<commit_msg>Added bool to enable/disable time tracking<commit_after>import time

TIMY = 'Timy'
TRACKING = True

class Timer(object):

    def __init__(self, ident=TIMY):
        self.ident = ident
        self.start = 0

    def __enter__(self):
        self.start = time.time()
        return self

    def __exit__(self, type, value, traceback):
        if TRACKING:
            self.show('{:f}'.format(self.elapsed))

    @property
    def elapsed(self):
        return time.time() - self.start

    def track(self, name='track'):
        if TRACKING:
            self.show('({}) {:f}'.format(name, self.elapsed))

    def show(self, text):
        print('{} {} seconds'.format(self.ident, text))


def timer(ident=TIMY, loops=1):
    def _timer(function, *args, **kwargs):
        if not TRACKING:
            return function

        def wrapper(*args, **kwargs):
            times = []
            for _ in range(loops):
                start = time.time()
                result = function(*args, **kwargs)
                end = time.time()
                times.append(end - start)

            print('{} executed ({}) for {} time(s) in {:f} seconds'.format(
                ident, function.__name__, loops, sum(times)))
            print('{} best time was {:f} seconds'.format(ident, min(times)))
            return result

        return wrapper
    return _timer
{'fraction_non_alphanumeric': 0.1426905132192846, 'fraction_numerical': 0.0015552099533437014, 'mean_word_length': 2.0235017626321974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '62321', 'n_tokens_mistral': 774, 'n_tokens_neox': 733, 'n_words': 195}