<commit_before>import django.template.loader
import django.conf
from timeit import Timer
import sys
import profile
import cProfile
import pyinstrument

sys.path.append('django_test')
django.conf.settings.configure(INSTALLED_APPS=(), TEMPLATES=[{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS':['./examples'],
}])
django.setup()

def test_func_template():
    django.template.loader.render_to_string('template.html')

t = Timer(stmt=test_func_template)
test_func = lambda: t.repeat(number=2000)

# base
base_timings = test_func()

# # profile
# p = profile.Profile()
# profile_timings = p.runcall(lambda: test_func())

# cProfile
cp = cProfile.Profile()
cProfile_timings = cp.runcall(test_func)

# pyinstrument 
profiler = pyinstrument.Profiler()
profiler.start()
pyinstrument_timings = test_func()
profiler.stop()

# pyinstrument timeline
# profiler = pyinstrument.Profiler(timeline=True)
# profiler.start()
# pyinstrument_timeline_timings = test_func()
# profiler.stop()

with open('out.html', 'w') as f:
    f.write(profiler.output_html())

print(profiler.output_text(unicode=True, color=True))

graph_data = (
    ('Base timings', min(base_timings)),
    # ('profile', min(profile_timings)),
    ('cProfile', min(cProfile_timings)),
    ('pyinstrument', min(pyinstrument_timings)),
    # ('pyinstrument timeline', min(pyinstrument_timeline_timings)),
)

from ascii_graph import Pyasciigraph

graph = Pyasciigraph(float_format='{0:.3f}')
for line in graph.graph('Profiler overhead', graph_data):
    print(line)
<commit_msg>Overhead iterations match README<commit_after>import django.template.loader
import django.conf
from timeit import Timer
import sys
import profile
import cProfile
import pyinstrument

sys.path.append('django_test')
django.conf.settings.configure(INSTALLED_APPS=(), TEMPLATES=[{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS':['./examples'],
}])
django.setup()

def test_func_template():
    django.template.loader.render_to_string('template.html')

t = Timer(stmt=test_func_template)
test_func = lambda: t.repeat(number=4000)

# base
base_timings = test_func()

# # profile
# p = profile.Profile()
# profile_timings = p.runcall(lambda: test_func())

# cProfile
cp = cProfile.Profile()
cProfile_timings = cp.runcall(test_func)

# pyinstrument 
profiler = pyinstrument.Profiler()
profiler.start()
pyinstrument_timings = test_func()
profiler.stop()

# pyinstrument timeline
# profiler = pyinstrument.Profiler(timeline=True)
# profiler.start()
# pyinstrument_timeline_timings = test_func()
# profiler.stop()

with open('out.html', 'w') as f:
    f.write(profiler.output_html())

print(profiler.output_text(unicode=True, color=True))

graph_data = (
    ('Base timings', min(base_timings)),
    # ('profile', min(profile_timings)),
    ('cProfile', min(cProfile_timings)),
    ('pyinstrument', min(pyinstrument_timings)),
    # ('pyinstrument timeline', min(pyinstrument_timeline_timings)),
)

from ascii_graph import Pyasciigraph

graph = Pyasciigraph(float_format='{0:.3f}')
for line in graph.graph('Profiler overhead', graph_data):
    print(line)

{'fraction_non_alphanumeric': 0.13925263494091344, 'fraction_numerical': 0.0038326413286489938, 'mean_word_length': 6.25, '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': '2181916', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1075, 'n_words': 191}