<commit_before><commit_msg>Profiling test<commit_after>__doc__ = u"""
    >>> import os, tempfile, cProfile as profile, pstats
    >>> statsfile = tempfile.mkstemp()[1]
    >>> profile.runctx("test_profile(100)", locals(), globals(), statsfile)
    >>> s = pstats.Stats(statsfile)
    >>> short_stats = dict([(k[2], v[1]) for k,v in s.stats.items()])
    >>> short_stats['f_def']
    100
    >>> short_stats['f_cdef']
    100
    >>> short_stats['f_inline']
    Traceback (most recent call last):
    ...
    KeyError: 'f_inline'
    >>> short_stats['f_inline_prof']
    100
    >>> short_stats['f_noprof']
    Traceback (most recent call last):
    ...
    KeyError: 'f_noprof'
    >>> short_stats['f_raise']
    100
    >>> os.unlink(statsfile)
"""

cimport cython

def test_profile(long N):
    cdef long i, n = 0
    for i from 0 <= i < N:
        n += f_def(i)
        n += f_cdef(i)
        n += f_inline(i)
        n += f_inline_prof(i)
        n += f_noprof(i)
        try:
            n += f_raise(i+2)
        except RuntimeError:
            pass
    return n

def f_def(long a):
    return a

cdef long f_cdef(long a):
    return a

cdef inline long f_inline(long a):
    return a

@cython.profile(True)
cdef inline long f_inline_prof(long a):
    return a

@cython.profile(False)
cdef int f_noprof(long a):
    return a

cdef long f_raise(long) except -2:
    raise RuntimeError
{'fraction_non_alphanumeric': 0.1445003594536305, 'fraction_numerical': 0.015815959741193385, 'mean_word_length': 2.6728232189973613, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, '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': '1046010', 'n_tokens_mistral': 525, 'n_tokens_neox': 507, 'n_words': 124}