<commit_before>__author__ = '<NAME>, <EMAIL>'

""" This example demonstrates how to profile an OPF problem. """

from os.path import join, dirname

from hotshot import Profile
from hotshot import stats

import pylon.case
from pylon import Case, OPF

# Define a path to the data file.
CASE_FILE = join(dirname(pylon.case.__file__), "test", "data", "case30pwl.pkl")

# Load the data file.
case = Case.load(CASE_FILE)

prof = Profile("hotshot_opf_stats")
prof.runcall(OPF(case, dc=False, opt={"verbose": True}).solve)
prof.close()

st = stats.load("hotshot_opf_stats")
st.strip_dirs()
st.sort_stats('time', 'calls')
st.print_stats()<commit_msg>Using cProfile in example.<commit_after>__author__ = '<NAME>, <EMAIL>'

""" This example demonstrates profiling an OPF problem. """

from os.path import join, dirname

import cProfile
import pstats

import pylon.case
from pylon import Case, OPF #@UnusedImport

# Define a path to the data file.
CASE_FILE = join(dirname(pylon.case.__file__), "test", "data", "case30pwl.pkl")

# Load the data file.
case = Case.load(CASE_FILE)

cProfile.run("OPF(case, dc=False, opt={'verbose': True}).solve()", "opf_prof")

p = pstats.Stats("opf_prof")
#p.sort_stats('name').print_stats()
p.sort_stats('cumulative').print_stats(20)
#p.sort_stats('time').print_stats(20)
#p.sort_stats('time', 'cum').print_stats(.5, 'init')
{'fraction_non_alphanumeric': 0.15601783060921248, 'fraction_numerical': 0.006686478454680535, 'mean_word_length': 5.943298969072165, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 7, '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': '2053690', 'n_tokens_mistral': 483, 'n_tokens_neox': 474, 'n_words': 123}