<commit_before>import time
from random import randrange as rr


def run_trials(func, trials=3):
    """Runs a set of trials given a function and trial number.
    The `func` in question is expected to use the test_speed decorator
    to do the actual profiling."""
    for num in range(trials):
        print('Running trial #{}'.format(num))
        func(num)
        print('------------------------\n')


def run_sorting_trials(
        sorting_func, magnitudes=[10, 100, 1000], test_output=True):
    """Runs a bunch of trials of various magnitudes with a given
    func, using randomly generated numbers.
    Returns a dict of results for later inspection.
    Tailored specifically for sorting functions, by
    generating randomly mixed sequences of numbers."""
    results = {
        'function': sorting_func.func_name if hasattr(
            sorting_func, 'func_name') else 'builtin'
    }
    for magnitude in magnitudes:
        start = time.time()
        items = [rr(0, 999) for _ in range(magnitude)]
        sorted_res = sorting_func(items)
        end = time.time()
        results[magnitude] = {'time': end - start}
        if test_output:
            results[magnitude]['correct'] = sorted(items) == sorted_res
    return results


def _test_speed(func, *args, **kwargs):
    """Decorator that wraps a function and provides a timer
    + results output for execution profiling."""
    def _inner(*args, **kwargs):
        divider = '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
        print(divider)
        print('starting... {}'.format(func))
        start = time.time()
        res = func(*args, **kwargs)
        end = time.time()
        print('function took {}s'.format(end - start))
        print(divider)
        return res
    return _inner<commit_msg>Add decorator wraps<commit_after>import time
from random import randrange as rr
from functools import wraps


def run_trials(func, trials=3):
    """Runs a set of trials given a function and trial number.
    The `func` in question is expected to use the test_speed decorator
    to do the actual profiling."""
    for num in range(trials):
        print('Running trial #{}'.format(num))
        func(num)
        print('------------------------\n')


def run_sorting_trials(
        sorting_func, magnitudes=[10, 100, 1000], test_output=True):
    """Runs a bunch of trials of various magnitudes with a given
    func, using randomly generated numbers.
    Returns a dict of results for later inspection.
    Tailored specifically for sorting functions, by
    generating randomly mixed sequences of numbers."""
    results = {
        'function': sorting_func.func_name if hasattr(
            sorting_func, 'func_name') else 'builtin'
    }
    for magnitude in magnitudes:
        start = time.time()
        items = [rr(0, 999) for _ in range(magnitude)]
        sorted_res = sorting_func(items)
        end = time.time()
        results[magnitude] = {'time': end - start}
        if test_output:
            results[magnitude]['correct'] = sorted(items) == sorted_res
    return results


def _test_speed(func, *args, **kwargs):
    """Decorator that wraps a function and provides a timer
    + results output for execution profiling."""
    @wraps(func)
    def _inner(*args, **kwargs):
        divider = '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
        print(divider)
        print('starting... {}'.format(func))
        start = time.time()
        res = func(*args, **kwargs)
        end = time.time()
        print('function took {}s'.format(end - start))
        print(divider)
        return res
    return _inner
{'fraction_non_alphanumeric': 0.13305439330543933, 'fraction_numerical': 0.007810320781032078, 'mean_word_length': 2.636916835699797, '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': '2800870', 'n_tokens_mistral': 1027, 'n_tokens_neox': 973, 'n_words': 340}