예제 #1
0
	def handle(self, *args, **options):
		if options['profile']:
			profiler = Profile()
			profiler.runcall(issue_cert)
			pstats.Stats(profiler).sort_stats('cumulative').print_stats(25)
			return
		issue_cert()
def stats_for_fib(type_, fib):
    p = Profile()
    p.runcall(fib, 30)
    p.dump_stats(type_.lower().replace(' ', '_') + '.stats')
    s = Stats(p)
    s.strip_dirs().sort_stats('time', 'cumulative')
    print_stats(type_, s)
예제 #3
0
 def handle(self, *args, **options):
     if options['profile']:
         profiler = Profile()
         profiler.runcall(self._handle, *args, **options)
         profiler.dump_stats('parse_gtfs.prof')
     else:
         self._handle(*args, **options)
예제 #4
0
파일: parse_pcap.py 프로젝트: rouge8/pig
 def handle(self, *args, **options):
     if options['profile']:
         profiler = Profile()
         profiler.runcall(self._handle, *args, **options)
         profiler.print_stats()
     else:
         self._handle(*args, **options)
예제 #5
0
 def handle(self, *args, **options):
     if options["profile"]:
         profiler = Profile()
         profiler.runcall(self._handle, *args, **options)
         profiler.dump_stats("import_games.profile")
     else:
         self._handle(*args, **options)
예제 #6
0
파일: Main.py 프로젝트: cournape/numscons
def _exec_main(parser, values):
    sconsflags = os.environ.get('SCONSFLAGS', '')
    all_args = string.split(sconsflags) + sys.argv[1:]

    options, args = parser.parse_args(all_args, values)

    if type(options.debug) == type([]) and "pdb" in options.debug:
        import pdb
        pdb.Pdb().runcall(_main, parser)
    elif options.profile_file:
        try:
            from cProfile import Profile
        except ImportError, e:
            from profile import Profile

        # Some versions of Python 2.4 shipped a profiler that had the
        # wrong 'c_exception' entry in its dispatch table.  Make sure
        # we have the right one.  (This may put an unnecessary entry
        # in the table in earlier versions of Python, but its presence
        # shouldn't hurt anything).
        try:
            dispatch = Profile.dispatch
        except AttributeError:
            pass
        else:
            dispatch['c_exception'] = Profile.trace_dispatch_return

        prof = Profile()
        try:
            prof.runcall(_main, parser)
        except SConsPrintHelpException, e:
            prof.dump_stats(options.profile_file)
            raise e
예제 #7
0
    def __call__(self, environ, start_response):
        response_body = []

        def catching_start_response(status, headers, exc_info=None):
            start_response(status, headers, exc_info)
            return response_body.append

        def runapp():
            appiter = self._app(environ, catching_start_response)
            response_body.extend(appiter)
            if hasattr(appiter, 'close'):
                appiter.close()

        p = Profile()
        p.runcall(runapp)
        body = ''.join(response_body)
        stats = Stats(p)
        stats.sort_stats(*self._sort_by)

        self._stream.write('-' * 80)
        self._stream.write('\nPATH: %r\n' % environ.get('PATH_INFO'))
        stats.print_stats(*self._restrictions)
        self._stream.write('-' * 80 + '\n\n')

        return [body]
예제 #8
0
    def handle(self, **options):
        """
        Django entry point.
        """
        def validate_options():
            """
            Validate command line options.
            """
            if not options['destination']:
                raise CommandError('Please specify the --destination option')

            if not options['format']:
                raise CommandError('Please specify the --format option')

            if options['format'] in ['bed', 'all'] and not options['bedToBigBed']:
                raise CommandError('Please specify the --bedToBigBed option')

            if options['format'] not in self.formats:
                raise CommandError('Please choose a valid output format (%s)' % '|'.join(self.formats))

        validate_options()

        if options['profile']:
            profiler = Profile()
            profiler.runcall(self.export, **options)
            profiler.print_stats()
            profiler.dump_stats('profile.txt')            
        elif options['format'] == 'all':
            self.export_all(**options)
        else:
            self.export(**options)
예제 #9
0
 def handle(self, *args, **options):
     """ Handles the command line arguments - initiates profiling if set to true """
     if options.get('profile', False):
         profiler = Profile()
         profiler.runcall(self._handle, *args, **options)
         profiler.print_stats()
     else:
         self._handle(*args, **options)
예제 #10
0
    def handle(self, *args, **options):

        if options['profile_file']:
            profiler = Profile()
            profiler.runcall(self._handle, *args, **options)
            profiler.dump_stats(options['profile_file'])
        else:
            self._handle(*args, **options)
예제 #11
0
def run_profiler(testee, * args, ** kwargs):
    from cProfile import Profile
    profiler = Profile()
    
    test = lambda: testee(*args, ** kwargs)
    
    profiler.runcall(test)
    return profiler
예제 #12
0
 def handle(self, *args, **options):
     profile_file = options.pop('profile', None)
     if profile_file:
         profiler = Profile()
         profiler.runcall(self._handle, *args, **options)
         stats = Stats(profiler)
         stats.dump_stats(profile_file)
     else:
         self._handle(*args, **options)
예제 #13
0
def profile(func, stats_path):
    profiler = Profile()
    try:
        profiler.runcall(func)
    except KeyboardInterrupt:
        profiler.dump_stats(stats_path)
        s = pstats.Stats(stats_path)
        s.strip_dirs().sort_stats("time").print_stats(30)
        raise
예제 #14
0
    def test_xid_perfs(self):
        for i in range(10000):
            self.make(i)
        self.model.invalidate_cache()
        records = self.model.search([])

        p = Profile()
        p.runcall(records._export_rows, [['id'], ['value']])
        p.dump_stats('xid_perfs.pstats')
def stats_for_main():
    p = Profile()
    p.runcall(main)
    p.dump_stats('main.stats')
    s = Stats(p)
    s.strip_dirs().sort_stats('time', 'cumulative')
    print_stats('MAIN - ALL STATS', s)
    print_stats('MAIN - CALLERS', s, 'sleep')
    print_stats('MAIN - CALLEES', s, 'heavy')
예제 #16
0
 def handle(self, *args, **options):
     # run with profiling
     if options['profile']:
         profiler = Profile()
         profiler.runcall(self._handle, *args, **options)
         profiler.print_stats()
     # run without profiling
     else:
         self._handle(*args, **options)
예제 #17
0
def profile():
    from cProfile import Profile
    import time
    p = Profile(profile_time)
    p.runcall(main)
    import lsprofcalltree
    k = lsprofcalltree.KCacheGrind(p)
    k.output(open('prof.kgrind', 'w+b'))
    print "Profile results written to prof.kgrind"
예제 #18
0
파일: profile.py 프로젝트: 280185386/sentry
def profile_call(_func, *args, **kwargs):
    p = Profile()
    rv = []
    p.runcall(lambda: rv.append(_func(*args, **kwargs)))
    p.dump_stats('/tmp/sentry-%s-%s.prof' % (time.time(), _func.__name__))

    stats = Stats(p, stream=sys.stderr)
    stats.sort_stats('time', 'calls')
    stats.print_stats()
    return rv[0]
예제 #19
0
 def profile(self, func, suffix=''):
     from cProfile import Profile
     prof_file = '%s%s' % (func.__name__, suffix)
     try:
         os.unlink(prof_file)
     except OSError:
         pass
     prof = Profile()
     prof.runcall(func)
     prof.dump_stats(prof_file)
예제 #20
0
파일: driver.py 프로젝트: gimac/pyrticle
 def run(self):
     if self.setup.profile_output_filename is not None:
         from cProfile import Profile
         prof = Profile()
         try:
             prof.runcall(self.inner_run)
         finally:
             from lsprofcalltree import KCacheGrind
             kg = KCacheGrind(prof)
             kg.output(open(self.setup.profile_output_filename, "w"))
     else:
         self.inner_run()
예제 #21
0
    def handle(self, *args, **options):
        if options['profile']:
            profiler = Profile()
            s = StringIO.StringIO()

            profiler.runcall(self._handle, *args, **options)

            # Sort profiled functions by cumulative time spent in function
            pstats.Stats(profiler, stream=s).sort_stats('cumulative').print_stats()
            print s.getvalue()
        else:
            Command._handle(*args, **options)
예제 #22
0
파일: utils.py 프로젝트: rmoorman/lektor
def profile_func(func):
    from cProfile import Profile
    from pstats import Stats

    p = Profile()
    rv = []
    p.runcall(lambda: rv.append(func()))
    p.dump_stats('/tmp/lektor-%s.prof' % func.__name__)

    stats = Stats(p, stream=sys.stderr)
    stats.sort_stats('time', 'calls')
    stats.print_stats()

    return rv[0]
예제 #23
0
def profile_call(func, *args, **kw):
    from cProfile import Profile
    p = Profile() #clock)
    print "Profiling to", profile_filename
    p.runcall(func, *args, **kw)

    from pytools import lsprofcalltree
    k = lsprofcalltree.KCacheGrind(p)
    pdump_filename = profile_filename+'.pstats'
    p.dump_stats(pdump_filename)
    print "Profile dumped to", pdump_filename
    kcache_grind_filename = profile_filename+'.kcachegrind'
    with open(kcache_grind_filename, 'w+b') as f:
        k.output(f)
    print "Profile results written to", kcache_grind_filename
예제 #24
0
    def __call__(self, environ, start_response):
        key_morsel = Cookie(environ.get("HTTP_COOKIE", "")).get(self.toggle_key)
        # useful vars
        query = query_str2dict(environ.get("QUERY_STRING"))
        enable_by_cookie = key_morsel.value == self.enable_value if key_morsel else False
        enable_by_query = query.get(self.toggle_key) == self.enable_value
        # pop toggle_key from query dic to avoid case: '?_profile=on&_profile='
        disable = query.pop(self.toggle_key, None) == ""  # only can be disabled by query
        enable = not disable and (enable_by_query or enable_by_cookie)

        run_app, resp_body, saved_ss_args = self._intercept_call()

        # processing cookies and queries
        so = query.pop(self.SIMPLE_OUTPUT_TOGGLE_KEY, None)
        if so is not None:
            self.simple_output = so == "True"
        cookie_to_set = None
        if enable_by_query and not enable_by_cookie:
            cookie_to_set = "%s=%s; Path=/; HttpOnly" % (self.toggle_key, self.enable_value)
        elif disable:
            cookie_to_set = "%s=; Path=/; Max-Age=1; HttpOnly" % self.toggle_key

        if enable:
            start = time.time()
            profile = Profile()
            profile.runcall(run_app, environ)  # here we call the WSGI app
            elapsed = time.time() - start
        else:
            profile = elapsed = None  # for annoying IDE
            run_app(environ)

        status, headers = saved_ss_args[:2]
        headers_dic = Headers(headers)
        if cookie_to_set:
            headers_dic.add_header("Set-Cookie", cookie_to_set)

        # insert result into response
        content_type = headers_dic.get("Content-Type", "")
        if enable and status.startswith("200") and content_type.startswith("text/html"):
            environ["QUERY_STRING"] = dict2query_str(query)

            matched = _find_charset.match(content_type)
            encoding = matched.group(1) if matched else "ascii"
            rendered = self.render_result(profile, elapsed, environ).encode(encoding, "replace")
            resp_body = [insert_into_body(rendered, b"".join(resp_body))]
            headers_dic["Content-Length"] = str(len(resp_body[0]))
        start_response(status, headers, saved_ss_args[2] if len(saved_ss_args) == 3 else None)
        return resp_body
예제 #25
0
 def intprofiled(*n, **kw):
     prof = Profile(timer=timer)
     a = prof.runcall(eff, *n, **kw)
     TRACE('Dumping profile stats to: %r' % (outputfile,))
     prof.dump_stats(outputfile)
     TRACE('Profile run: %d' % timer())
     return a
예제 #26
0
파일: util.py 프로젝트: zbing3/appengine
def prof_call(func, *args):
    # TODO 这里需要测试兼容性
    # 输出函数调用性能分析。
    prof = Profile(builtins=False)
    ret = prof.runcall(func, *args)
    Stats(prof).sort_stats("time").print_stats("/action/", 10)
    return ret
예제 #27
0
 def decorator(*args, **kwargs):
     if should_profile and not should_profile():
         return func(*args, **kwargs)
     result = None
     if cumulative:
         global profiler
     else:
         profiler = Profile()
     try:
         result = profiler.runcall(func, *args, **kwargs)
     finally:
         if lock.acquire(False):
             if dump_stats:
                 profiler.dump_stats(profile_filename)
             if callgrind_filename:
                 stats = pstats.Stats(profiler)
                 conv = pyprof2calltree.CalltreeConverter(stats)
                 with open(callgrind_filename, 'w') as fd:
                     conv.output(fd)
                 if print_stats:
                     stats.strip_dirs().sort_stats(
                         sort_stats).print_stats(print_stats)
             lock.release()
             return result
     return result
예제 #28
0
파일: util.py 프로젝트: windprog/appengine
def prof_call(func, *args):
    # 输出函数调用性能分析。
    from .config import settings
    prof = Profile(builtins=False)
    ret = prof.runcall(func, *args)
    Stats(prof).sort_stats("time").print_stats(settings.PROJECT_PATH, 10)
    return ret
예제 #29
0
    def profile_function(self, func, args, kwargs, profile_name):
        """
        Profile a Proteus function using the call: func(*args, **kwargs)

        Returns the output of the function call.
        """

        comm = self.comm
        if type(comm) is None:
            raise ValueError("The Dispatcher does not have a valid Comm object")

        prof = Profile()
        func_return = prof.runcall(func, *args, **kwargs)
        profile_rank_name = profile_name + str(comm.rank())
        stripped_profile_name = profile_name + '_c' + str(comm.rank())

        prof.dump_stats(profile_rank_name)
        comm.beginSequential()
        stats = pstats.Stats(profile_rank_name)
        stats.strip_dirs()
        stats.dump_stats(stripped_profile_name)
        stats.sort_stats('cumulative')
        if verbose and comm.isMaster():
            stats.print_stats(30)
            stats.sort_stats('time')
            if verbose and comm.isMaster():
                stats.print_stats(30)
        comm.endSequential()

        return func_return
예제 #30
0
파일: test.py 프로젝트: jimenaRL/espaces
def profiling():

    from cProfile import Profile
    from pstats import Stats

    ir_params = {  'ev_params'      : {'space':'e3', 'F': [0.1,0.1,0.1], 'j_max':30},
                   'duration'       : 1,
                   'nu'             : 1.7e-5,
                   'sampling_rate'  : 8000,
                }

    p = Profile()
    p.runcall(lambda : get_ir(ir_params))
    stats = Stats(p, stream=sys.stdout)
    stats.sort_stats('time')
    stats.print_stats(10)
예제 #31
0
# def sample_test():
    # print ('hi there')

def extract_algs_sm_in_shortstacks(provided_list):
    provided_list = list(set(provided_list))
    result = "\shortstack[l]{"
    list_length = len(provided_list)
    for idx, el in enumerate(provided_list):
        result += el
        if idx < (list_length - 1):
            result += '/'
        if idx % 2 != 0 and idx > 0:
            if idx < (list_length - 1):
                result += '\\\\'
    result += "}"
    return result
if __name__ == '__main__':

    # print (extract_algs_sm_in_shortstacks(['SMOTE', 'TN', 'CNN', 'ASD', 'VGZZ']))


    # latex_dict = large_func()
    # generate_latex_output(latex_dict)
    profiler = Profile()
    profiler.runcall(large_func)
    stats = Stats(profiler)
    stats.strip_dirs()
    stats.sort_stats('cumulative')
    stats.print_stats()
    # classify()
    # large_func()
예제 #32
0
        # 优化后
        # new_nums = [x for x in nums if 1000 < x < 2000 or 100 < x < 20]
        lists = []
        for x in nums:
            if 10 < x < 20 or 1000 < x < 2000:
                # print(x)
                lists.append(x)
        print(lists)


def and_work():
    nums = range(2000)

    for i in range(10000):
        # 优化前
        new_nums = [x for x in nums if x % 2 == 0 and x > 1900]
        # 优化后
        # new_nums = [x for x in nums if x > 1900 and x % 2.txt == 0]


def work():
    or_work()
    and_work()


if __name__ == '__main__':
    prof = Profile()
    prof.runcall(work)
    prof.print_stats()

# 原文链接:https://blog.csdn.net/Herishwater/article/details/99656200
예제 #33
0
파일: testcase.py 프로젝트: XakerS/PyCraft
 def profile(*args, **kwargs):
     profiler = Profile()
     try:
         return profiler.runcall(func, *args, **kwargs)
     finally:
         profiler.dump_stats(filename)
예제 #34
0
from pstats import Stats


def insertion_sort(data):
    result = []
    for value in data:
        insert_value(result, value)
    return result


def insert_value(array, value):
    for i, existing in enumerate(array):
        if existing > value:
            array.insert(i, value)
            return
    array.append(value)


max_size = 10**4
data = [randint(0, max_size) for _ in range(10)]
print(data)
result = insertion_sort(data)
print(result)

profiler = Profile()
profiler.runcall(lambda: insertion_sort(data))

stats = Stats(profiler)
stats.strip_dirs()
stats.sort_stats('cumulative')
stats.print_stats()
Author Email:           [email protected]
URL:                    https://github.com/DingGuodong/LinuxBashShellScriptForOps
Download URL:           https://github.com/DingGuodong/LinuxBashShellScriptForOps/tarball/master
Create Date:            2017/12/11
Create Time:            19:31
Description:            The Python Profiler
Long Description:       
References:             [the Python Library Reference](https://docs.python.org/2/library/profile.html)
Prerequisites:          []
Development Status:     3 - Alpha, 5 - Production/Stable
Environment:            Console
Intended Audience:      System Administrators, Developers, End Users/Desktop
License:                Freeware, Freely Distributable
Natural Language:       English, Chinese (Simplified)
Operating System:       POSIX :: Linux, Microsoft :: Windows
Programming Language:   Python :: 2.6
Programming Language:   Python :: 2.7
Topic:                  Utilities
 """
from cProfile import Profile


def main():
    pass


if __name__ == '__main__':
    prof = Profile()
    prof.runcall(main)
    prof.print_stats()
예제 #36
0
from pennpaper import Metric, plot_group

import math
import random


def many_plots():
    def one_series(shift):
        metrics = [Metric('x', 'y') for x in range(10)]
        for m in metrics:
            for i in range(40000):
                m.add_record(i,
                             random.random() + shift + 0.4 * math.sin(i / 200))
            m._sort()

        return sum(metrics)

    many = {f"random line {i}": one_series(i) for i in range(5)}

    plot_group(many, 'temp', name="many_series")


from cProfile import Profile

p = Profile()
p.runcall(many_plots)
p.print_stats('cumulative')
예제 #37
0

from djangoext import django_loader, DjangoContext
def test_django():
    # not cached because django is not thread safe and does
    # not cache by itself so it would be unfair to cache it here.
    django_template = django_loader.get_template('index.html')
    django_template.render(DjangoContext(context))


def test_genshi():
    genshi_template.generate(**context).render('html', doctype='html')


if __name__ == '__main__':
    sys.stdout.write('Realworldish Benchmark:\n')
    for test in 'jinja', 'mako', 'django', 'genshi':
        t = Timer(setup='from __main__ import test_%s as bench' % test,
                  stmt='bench()')
        sys.stdout.write(' >> %-20s<running>' % test)
        sys.stdout.flush()
        sys.stdout.write('\r    %-20s%.4f seconds\n' % (test, t.timeit(number=200) / 200))

    if '-p' in sys.argv:
        print('Jinja profile')
        p = Profile()
        p.runcall(test_jinja)
        stats = Stats(p)
        stats.sort_stats('time', 'calls')
        stats.print_stats()
예제 #38
0
    pass


def first_func():
    for _ in range(1000):
        my_utility(4, 5)


def second_func():
    for _ in range(10):
        my_utility(1, 3)


def my_program():
    for _ in range(20):
        first_func()
        second_func()


def test():
    return my_program()


profiler = Profile()
profiler.runcall(test)  # test()라고 치면 안된다 >> parameter가 있는 함수는 runcall에 쓸 수 없다!
stats = Stats(profiler)
stats.strip_dirs()  # dir(파일 경로)을 제거해준다
stats.sort_stats('cumulative')
stats.print_stats(10)
# tottime:총 시간 // percall: 한 번 반복시 걸린 시간 //
# cumtime: 하위 function들까지 고려한 시간 // percall: 하위 function들까지 고려해서 한번 반복시 걸린 시간
예제 #39
0
import os
from cProfile import Profile

# make a miniature model for playing on a miniature 7x7 board
architecture = {'filters_per_layer': 32, 'layers': 4, 'board': 7}
features = [
    'board', 'ones', 'turns_since', 'liberties', 'capture_size',
    'self_atari_size', 'liberties_after', 'sensibleness'
]
policy = CNNPolicy(features, **architecture)

datadir = os.path.join('benchmarks', 'data')
modelfile = os.path.join(datadir, 'mini_rl_model.json')
weights = os.path.join(datadir, 'init_weights.hdf5')
outdir = os.path.join(datadir, 'rl_output')
stats_file = os.path.join(datadir, 'reinforcement_policy_trainer.prof')

if not os.path.exists(datadir):
    os.makedirs(datadir)
if not os.path.exists(weights):
    policy.model.save_weights(weights)
policy.save_model(modelfile)

profile = Profile()
arguments = (modelfile, weights, outdir, '--learning-rate', '0.001',
             '--save-every', '2', '--game-batch', '20', '--iterations', '10',
             '--verbose')

profile.runcall(run_training, arguments)
profile.dump_stats(stats_file)
예제 #40
0
                               elite_size=elite_size,
                               mutation_rate=mutation_rate)

    # max_injections = 20
    # injections = 0

    ga.run()

    return ga.population[0]


from cProfile import Profile
profiler = Profile()
profiler.runcall(one_run,
                 popsize=50,
                 epochs=int(2000),
                 elite_size=1,
                 mutation_rate=8e-3)

profiler.print_stats('cumulative')

# import time
# t = time.time()
# for popsize in [10, 30, 80]:
#     for mutation_rate in [5e-3, 8e-3, 2e-2]:
#         one_run(popsize=popsize,
#                 epochs=int( 1e6 // popsize),
#                 elite_size=min(popsize//4,15) + popsize//25,
#                 mutation_rate= mutation_rate)
#         print(time.time()-t)
#         t = time.time()
예제 #41
0
def second_func():
    for _ in range(10):
        my_utility(1, 3)


def my_program():
    for _ in range(20):
        first_func()
        second_func()


if __name__ == "__main__":
    from random import randint

    max_size = 10**4
    data = [randint(0, max_size) for _ in range(max_size)]
    test = lambda: my_program()
    from cProfile import Profile
    profiler = Profile()
    profiler.runcall(test)
    from pstats import Stats
    stats = Stats(profiler)
    stats.strip_dirs()
    stats.sort_stats('cumulative')
    stats.print_stats()
    print(
        "########################\n#######################\n#################")

    stats.print_callers()
예제 #42
0
对循环的优化所遵循的原则是尽量减少循环过程中的计算量,
循环之外能做的事不要放在循环内
"""
from cProfile import Profile

def loop_work():
    list_a = list(range(100))
    list_b = list(range(100))

    len_a = len(list_a)
    len_b = len(list_b)

    #循环优化前
    # for i in range(10000):
    #     for i in range(len(list_a)):
    #         for j in range(len(list_b)):
    #             x = list_a[i] + list_b[j]
    #循环优化后
    for i in range(10000):
        for i in range(len_a):
            x = list_a[i]
            for j in range(len_b):
                x += list_b[j]


if __name__ == '__main__':
    prof = Profile()
    prof.runcall(loop_work)
    prof.print_stats()

# 原文链接:https://blog.csdn.net/Herishwater/article/details/99656200
예제 #43
0
파일: 447.py 프로젝트: Tsumida/dsalgo
def test_profile():
    s = Solution()
    assert 0 == s.numberOfBoomerangs(points=[])
    assert 2 == s.numberOfBoomerangs(points=[[0, 0], [1, 0], [2, 0]])
    points = [[489, 238], [323, 460], [853, 965], [327, 426], [264, 871],
              [580, 947], [362, 275], [241, 772], [967, 240], [68, 847],
              [825, 703], [922, 898], [769, 217], [23, 160], [472, 802],
              [755, 313], [40, 78], [125, 246], [396, 452], [672, 660],
              [323, 253], [607, 37], [880, 201], [161, 847], [441, 229],
              [46, 266], [284, 320], [516, 53], [889, 539], [565, 713],
              [341, 320], [26, 381], [751, 504], [979, 147], [956, 652],
              [807, 632], [257, 767], [669, 489], [968, 831], [336, 409],
              [60, 734], [27, 697], [54, 543], [750, 944],
              [82, 668], [657, 423], [988, 36], [156, 91], [540, 136],
              [238, 496], [140, 398], [128, 397], [165, 150], [238, 133],
              [981, 926], [894, 393], [660, 921], [90, 66], [464, 193],
              [10, 898], [861, 20], [321, 201], [408, 829], [293, 948],
              [965, 531], [796, 457], [929, 277], [206, 446], [427, 444],
              [931, 760], [370, 825], [153, 30], [98, 244], [449, 914],
              [789, 811], [812, 650], [831, 485], [203, 239], [315, 496],
              [539, 632], [380, 336], [442, 661], [613, 648], [108, 392],
              [93, 391], [152, 815], [217, 305], [198, 667], [901, 647],
              [934, 690], [458, 746], [692, 642], [584, 896], [233, 251],
              [744, 773], [235, 124], [109, 677], [786, 74], [326, 246],
              [466, 771], [989, 618], [586, 558], [923, 136], [226, 177],
              [783, 160], [867, 594], [258, 912], [236, 842], [808, 469],
              [445, 552], [242, 681], [29, 703], [358, 167], [777, 36],
              [765, 595], [807, 754], [213, 746], [313, 489], [882, 539],
              [666, 18], [51, 885], [612, 309], [149, 200], [504, 957],
              [669, 949], [862, 264], [630, 891], [319, 341], [410, 449],
              [377, 175], [44, 537], [929, 610], [635, 242], [99, 869],
              [133, 117], [887, 184], [354, 851], [846, 504], [51, 350],
              [813, 73], [651, 675], [337, 634], [918, 656], [975, 328],
              [105, 704], [503, 502], [241, 785], [112, 876], [27, 211],
              [98, 513], [680, 985], [697, 386], [189, 895], [890, 240],
              [245, 56], [313, 897], [83, 2], [531, 2], [659, 858], [682, 116],
              [562, 538], [618, 804], [323, 730], [32, 702], [293, 482],
              [215, 325], [468, 265], [64, 657], [160, 306], [249, 406],
              [362, 915], [655, 446], [917, 538], [800, 576], [396, 482],
              [45, 310], [20, 15],
              [466, 343], [98, 851], [46, 743], [333, 261], [421, 801],
              [878, 485], [810, 39], [791, 412], [797, 154], [327, 452],
              [600, 244], [342, 400], [173, 90], [234, 570], [400, 255],
              [585, 867], [950, 683], [718, 996], [779, 51], [610, 200],
              [205, 488], [685, 367], [879, 476], [779, 676], [982, 458],
              [128, 934], [703, 822], [686, 228], [912, 921], [798, 313],
              [176, 735], [180, 478], [771, 898], [475, 550], [301, 437],
              [750, 506], [277, 787], [226, 157], [615, 5], [833, 598],
              [816, 314], [532, 519], [136, 219], [99, 49], [492, 249],
              [362, 20], [984, 894], [498, 755], [144, 325], [657, 445],
              [762, 407], [304, 392], [546, 530], [549, 162], [887, 734],
              [760, 703], [48, 644], [574, 537], [215, 673], [938, 707],
              [922, 652], [727, 259], [546, 226], [14, 42], [551, 24],
              [487, 666], [783, 143], [58, 330], [673, 959], [492, 913],
              [693, 604], [616, 94], [248, 191], [631, 816], [216, 569],
              [523, 491], [573, 603], [750, 119], [181, 116], [513, 84],
              [140, 0], [750, 924], [496, 160], [254, 521], [119, 98],
              [434, 165], [702, 51], [259, 302], [594, 242], [118, 810],
              [163, 994], [653, 736], [597, 403], [207, 778], [520, 720],
              [862, 12], [72, 965], [936, 568], [125, 542], [442, 597],
              [640, 876], [762, 694], [279, 373], [997, 225], [967, 467],
              [388, 130], [461, 41], [218, 410], [445, 425], [540, 317],
              [497, 403], [329, 569], [720, 266], [490, 197], [808, 932],
              [146, 801], [160, 260], [495, 440], [633, 844], [17, 600],
              [312, 405], [82, 125], [447, 300], [536, 244], [77, 76],
              [561, 574], [831, 890], [144, 903], [508, 986], [101, 669],
              [918, 599], [470, 78], [860, 965], [870, 845], [810, 888],
              [446, 122], [645, 880], [599, 92], [181, 487], [688, 610],
              [916, 249], [185, 747], [492, 681], [3, 352], [667, 456],
              [21, 937], [55, 491], [15, 915], [457, 238], [761, 267],
              [478, 559], [741, 123], [439, 692], [568, 972], [180, 256],
              [935, 96], [858, 120], [195, 702], [801, 198], [54, 820],
              [654, 76], [757, 62], [567, 772], [977, 376], [362, 90],
              [995, 840], [1, 88], [316, 793], [781, 884], [765, 961],
              [492, 700], [57, 702], [172, 604], [404, 325], [803, 459],
              [145, 809], [887, 902], [871, 454], [27, 201], [183, 741],
              [643, 178], [582, 645], [267, 250], [438, 48], [134, 555],
              [361, 978], [608, 770], [681, 780], [374, 437], [106, 529],
              [896, 603], [339, 135], [858, 562], [590, 885], [115, 125],
              [626, 759], [303, 560], [404, 922], [810, 842], [970, 296],
              [397, 683], [627, 5], [453, 308], [138, 828], [745, 596],
              [709, 994], [199, 48], [129, 57], [963, 71], [294,
                                                            78], [196, 273],
              [189, 852], [833, 593], [774, 996], [787, 97], [644, 537],
              [780, 271], [894, 234], [579, 32], [414, 677], [628, 123],
              [23, 180], [524, 504], [589, 487], [576, 884], [917, 124],
              [157, 107], [976, 342], [52, 103], [690, 840], [200, 335],
              [377, 980], [606, 271], [566, 538], [656, 980], [567, 636],
              [456, 590], [168, 980], [94, 758], [819, 22], [994, 88],
              [147, 503], [195, 475], [197, 600], [578, 888], [792, 130],
              [223, 169], [463, 181], [792, 29], [719, 800], [10, 286],
              [789, 466], [228, 957], [798, 323], [715, 617], [697, 61],
              [705, 196], [564, 253], [672, 762], [205, 602], [650, 997],
              [85, 225], [518, 548], [406, 662], [577, 478], [463, 939],
              [116, 252], [757, 345], [561, 555], [20, 277], [524, 717],
              [690, 582], [914, 255], [187, 938], [17, 392], [892, 19],
              [741, 977], [596, 259], [525, 2], [273, 455], [832, 736],
              [394, 949], [340, 504], [294, 902], [59, 314], [531, 936],
              [383, 221], [870, 297], [828, 57], [587, 197], [801, 480],
              [568, 894], [457, 164], [153, 335], [519, 426], [790, 351],
              [515, 536], [652, 207], [40, 946], [461, 452], [612, 344],
              [388, 996], [918, 610], [645, 746], [19, 233], [296, 820],
              [65, 864], [66, 522], [29, 219], [209, 548], [997, 351],
              [251, 864], [888, 904], [72, 928], [202, 885], [732, 815],
              [230, 472], [163, 148], [82, 160], [246, 101], [745, 542],
              [273, 810], [407, 339]]

    profile = Profile()
    profile.runcall(s.numberOfBoomerangs, points=points)
    profile.print_stats()

    print("-" * 32)

    profile = Profile()
    profile.runcall(s.numberOfBoomerangs2, points=points)
    profile.print_stats()
예제 #44
0
    t = 0
    r = 0
    poel = po[1:-1]
    y = 0
    while y < l2:
        top = set()
        h = 0
        while h < l:
            if (y // (2**h)) % 2 == 1:
                top.add(poel[h])
            h += 1
        top.update({po[0], po[-1]})
        t += interunion(top)
        if t % 10 == 0:
            f = t // 10
            if r != f:
                print(t)
                r = f
        y += 1
    print(t)
    return t


profile = Profile()
n = int(input('input cardinal number of topology: '))
profile.runcall(checkdimen, n)
stats = Stats(profile)
stats.strip_dirs()
stats.sort_stats('cumulative')
stats.print_stats()
예제 #45
0
from AlphaGo.preprocessing.game_converter import game_converter
from cProfile import Profile

prof = Profile()

test_features = [
    "board", "turns_since", "liberties", "capture_size", "self_atari_size",
    "liberties_after", "sensibleness", "zeros"
]
gc = game_converter(test_features)
args = ('tests/test_data/sgf/Lee-Sedol-vs-AlphaGo-20160309.sgf', 19)


def run_convert_game():
    for traindata in gc.convert_game(*args):
        pass


prof.runcall(run_convert_game)
prof.dump_stats('bench_results.prof')
예제 #46
0
def _time_profile(fn):
    profiler = Profile()
    profiler.runcall(fn)
    stats = pstats.Stats(profiler)
    stats.sort_stats("time")
    stats.print_stats(40)
예제 #47
0
def prof_call(func, *args):
    # 输出函数调用性能分析。
    prof = Profile(builtins=False)
    ret = prof.runcall(func, *args)
    Stats(prof).sort_stats("time").print_stats("/action/", 10)
    return ret
예제 #48
0
去掉行#s_list = set(s_list)的注释,同样效率提升了一半。因此在需要多数据成员进行频繁的查找或者
访问的时候,使用 dict 或 set 是一个较好的选择。

"""

print(2**10)
from cProfile import Profile


def search():
    s_list = [
        'a', 'b', 'is', 'python', 'jason', 'hello', 'hill', 'with', 'phone',
        'test', 'dfdf', 'apple', 'pddf', 'ind', 'basic', 'none', 'baecr',
        'var', 'bana', 'dd', 'wrd'
    ]

    # s_list = dict.fromkeys(s_list,True)
    # s_list = set(s_list)
    results = []

    for i in range(1000000):
        for s in ['is', 'hat', 'new', 'list', 'old', '.']:
            if s not in s_list:
                results.append(s)


if __name__ == '__main__':
    prof = Profile()
    prof.runcall(search)
    prof.print_stats()
# 原文链接:https://blog.csdn.net/Herishwater/article/details/99656200
예제 #49
0
def do_test():
    x_array = [randint(-max_size, max_size) for _ in range(max_size)]
    y_array = [randint(-max_size, max_size) for _ in range(max_size)]

    matrix = calculate(x_array, y_array)
    '''
    for y in range(max_size):
        for x in range(max_size):
            print("{0:-10}".format(matrix[y][x]), end="")
        print("")
    '''


profiler = Profile()
profiler.runcall(do_test)

stats = Stats(profiler)
stats.strip_dirs()
stats.sort_stats("cumulative")

print("-" * 40)

stats.print_stats()

print("-" * 40)

stats.print_callees()

print("-" * 40)
import time


def slowfunc(goslow=False):
    l = []
    for i in range(100):
        l.append(i)
        if goslow:
            time.sleep(0.01)
    return l


from cProfile import Profile

profiler = Profile()
profiler.runcall(slowfunc, True)
profiler.print_stats()

profiler = Profile()
profiler.runcall(slowfunc, False)
profiler.print_stats()
예제 #51
0
    graph2 = [list(row) for row in nodes_map_raw.split()]
    nr = len(graph2)
    nc = len(graph2[0])
    bdbfs = BiDirBFS(nodes_map_raw)
    for i in bdbfs.step():
        pass
    if bdbfs.path:
        for y in xrange(nr):
            for x in xrange(nc):
                if (x, y) == bdbfs.source:
                    print 'S',
                elif (x, y) == bdbfs.target:
                    print 'T',
                elif (x, y) in bdbfs.path:
                    print '.',
                elif graph2[y][x] == BLOCKED:
                    print 'X',
                else:
                    print ' ',
            print
        print 'Route length:', len(bdbfs.path)
    else:
        print 'Failed to find the path'


if __name__ == '__main__':
    from cProfile import Profile
    p = Profile()
    p.runcall(_test)
    p.print_stats(sort=1)
예제 #52
0
import logging
from cProfile import Profile
from atpase import atpase, bgt

FILENAME = "atpase_profile.kgrind"
LOG = "profile.log"
profiler = Profile()
logger = bgt.logger
logger.setLevel(logging.INFO)
handler = logging.FileHandler(filename=LOG, mode='w')
logger.addHandler(handler)

try:
    profiler.runcall(atpase)
except KeyboardInterrupt as ex:
    handler.flush()
    raise ex
from pyprof2calltree import convert, visualize

convert(profiler.getstats(), FILENAME)
visualize(profiler.getstats())
예제 #53
0
def run(args):

    path = sys.argv[1]

    if '/' in path:
        path = '/'.join(path.split('/')[:-1]) + '/'
        path = "%s/%s" % (os.getcwd(), path)
    else:
        path = os.getcwd()

    sage.path = path

    home_path = os.path.expanduser('~')

    print(banner)
    observer = sage._log.startLogging(sys.stdout)
    observer.timeFormat = "%Y-%m-%d %H:%M:%S:%f"

    from sage.server import run as run_sage, setup_system

    setup_system()

    if args.app is None:
        # load app manifest?
        if args.manifest is None:
            if os.path.isfile(home_path + '/.sage-manifest'):
                sage.manifest.load(home_path + '/.sage-manifest')
            else:
                print('No default manifest file found. Creating %s' %
                      home_path + '/.sage-manifest')
                sage.manifest.create_template(home_path + '/.sage-manifest')
        else:
            sage.manifest.load(args.manifest)

        sage.apps.load_manifest()
    else:
        if os.path.exists('%s/%s.py' % (path, args.app)):
            path = '/'.join(path.split('/')[:-1])

        os.chdir(path)

        sys.path.append(path)

        sage.path = path
        sage.apps.load(args.app)

    if args.no_backdoor:
        sage.config.backdoor = False

    if args.no_telnet_proxy:
        sage.config.telnet_proxy = False

    if args.websockets:
        sage.config.ws_proxy = True

    if args.gmcp_debug:
        sage.config.gmcp_debug = True

    if args.profile:
        from cProfile import Profile
        profile = Profile()
        profile.runcall(run)
        profile.dump_stats(args.profile)
    else:
        run_sage()
예제 #54
0
    pass

def first_func():
    for _ in range(1000):
        my_utility(4, 5)

def second_func():
    for _ in range(10):
        my_utility(1, 3)

def my_program():
    for _ in range(20):
        first_func()
        second_func()

from cProfile import Profile
from pstats import Stats

profiler = Profile()
profiler.runcall(my_program)

stats = Stats(profiler)
stats.strip_dirs()
stats.sort_stats('cumulative')

# cannot recognize which calls which
stats.print_stats()

# can recognize which calls which
stats.print_callers()
if not os.path.exists(data_dir):
    os.makedirs(data_dir)
if not os.path.exists(ckpt_root):
    os.makedirs(ckpt_root)

network_architecture = {
    'filters_per_layer': 32,
    'layers': 4,
    'board': 9,
    "learning_rate": 0.05,
    'momentum': 0.9,
    'gpu_model': False
}
features = ['board']
model_config = {
    'model_file': model_file,
    'ckpt_path': ckpt_path,
    'weights_path': weights_path
}

policyValueNet = PolicyValueNet(features, model_config, **network_architecture)
#if not os.path.exists(weights_path):
#policyValueNet.save_weights(weights_path)
#policyValueNet.save_ckpts(ckpt_path, policyValueNet.get_global_step())
profile = Profile()
arguments = (model_file, weights_path, outdir, '--learning-rate', '0.001',
             '--save-every', '2', '--game-batch', '20', '--iter_start', '0',
             '--iterations', '2000', '--verbose')
profile.runcall(run_training, policyValueNet, arguments)
profile.dump_stats(stats_file)
예제 #56
0
    <title>${page_title|e}</title>
  </head>
  <body>
    <div class="header">
      <h1>${page_title|e}</h1>
    </div>
    <div class="table">
      <table>
      % for row in table
        <tr>
        % for cell in row
          <td>${testmacro(cell)}</td>
        % endfor
        </tr>
      % endfor
      </table>
    </div>
  </body>
</html>\
"""
jinja_template = JinjaEnvironment(line_statement_prefix='%',
                                  variable_start_string="${",
                                  variable_end_string="}").from_string(source)
print(jinja_template.environment.compile(source, raw=True))

p = Profile()
p.runcall(lambda: jinja_template.render(context))
stats = Stats(p)
stats.sort_stats('time', 'calls')
stats.print_stats()
예제 #57
0
파일: run.py 프로젝트: flying-circus/esec
def main():
    '''The main entry point for ``run.py``.
    '''
    # Check for arguments
    parser = optparse.OptionParser()
    # Options are ...
    parser.add_option('--nologo', action="store_true", default=False,
                      help="don't display banner and version info")
    parser.add_option('-o', '--optimise', action="store_true", default=False,
                      help='use psyco optimisation')
    parser.add_option('-p', '--profile', action="store_true", default=False,
                      help='use cProfile around simulation run')
    parser.add_option('-v', '--verbose', action="store", type="int", default="-1",
                      help='verbose level. 0=lowest, 5=highest. (Default config.)')
    # Single run settings
    parser.add_option('-c', '--config', metavar="NAMES", default='',
                      help='A set of configuration NAMES joined by "+" ')
    parser.add_option('-s', '--settings', metavar="NAMES", default='',
                      help='Override config settings. Quote and separate with ;.\n'+
                           'Values are eval()uated to support types.\n'+
                           'eg. -s "system.size=200; application.run_count=3" ')
    # Batch run setting
    parser.add_option('-b', '--batch', metavar="FILE", default='',
                      help='The name of a single batch file with optional\n'+
                           'tags joined by "+". Prefix tags with "!" to\n'+
                           'exclude them.')
    
    # Keep the processed options and any remaining items
    options, _ = parser.parse_args()
    
    if not options.nologo:
        # Banner
        print HR,
        print ' esec: EcoSystem Evolutionary Computation'
        print ' Copyright (c) Clinton Woodward and Steve Dower 2010-2011'
        print HR
    
    # Ignore some options under IronPython
    if is_ironpython():
        if options.optimise:
            warn("Cannot use Psyco under IronPython")
            options.optimise = False
        if options.profile:
            warn("Cannot profile under IronPython")
            options.profile = False
    
    # Optimise using Psyco?
    if options.optimise:
        try:
            import psyco
            psyco.full()
            print '  ** Psyco Optimisation! **'
        except ImportError:
            warn("Cannot import Psyco")
    
    # Batch run?
    if options.batch:
        esec_op = esec_batch
    # Single run?
    else:
        esec_op = esec_run
    
    # Profile this run?
    if options.profile:
        from cProfile import Profile
        print '  ** With profiling **'
        profiler = Profile()
        try:
            profiler.runcall(esec_op, options)
        finally:
            # Messy but necessary to redirect the profiler output to stderr instead
            # of stdout.
            import pstats
            pstats.Stats(profiler, stream=sys.stderr).sort_stats(-1).print_stats()
    else:
        esec_op(options)
예제 #58
0
from cProfile import Profile
from pstats import Stats
import sys
from janome.tokenizer import Tokenizer

repeat = 10
mmap = True
dump_file = 'tokenizer.profile'
if len(sys.argv) > 1 and sys.argv[1] == '-nommap':
    mmap = False
    dump_file = 'tokenizer_nommap.profile'

t = Tokenizer(mmap=mmap)

with open('text_lemon.txt') as f:
    s = f.read()

profiler = Profile()
profiler.runcall(lambda: [list(t.tokenize(s)) for i in range(repeat)])

stats = Stats(profiler)
stats.strip_dirs()
stats.sort_stats('tottime')
stats.print_stats()
stats.dump_stats(dump_file)
print(f'Result was dumped to {dump_file}.')
예제 #59
0
        stats1 = pstats.Stats(profile)
        stats.print_stats()
        return result

    except Exception as exception:
        raise exception


def main():
    """

    :return:
    """
    try:
        some_func(10, 20)

    except Exception as exception:
        raise exception


# to measure performance of a full function
profile = Profile()
profile.runcall(main)
stats = pstats.Stats(profile)
stats.print_stats()
stats.sort_stats()

# or we can run a function with Timer
Timer(some_func())

예제 #60
0
def _profile_callable_call(call, args, kwargs, is_profile_logged,
                           profile_filename) -> object:
    '''
    Profile the passed callable in a call-oriented deterministic manner with
    the passed positional and keyword arguments (if any), returning the value
    returned by this call and optionally logging and serializing the resulting
    profile to the file with the passed filename.

    See Also
    ----------
    :func:`profile_callable`
        Further details on function signature.
    '''

    # Log this fact.
    logs.log_debug('Call-granularity profiling enabled.')

    # Call-granularity profile of the subsequent call to this callable.
    profile = Profile()

    # Value returned by calling this callable with these arguments, storing a
    # profile of this call into this "profile" object.
    return_value = profile.runcall(call, *args, **kwargs)

    # If the caller requested this profile be logged...
    if is_profile_logged:
        # Maximum number of slowest callables to log, arbitrarily defined to be
        # twice the default number of rows in the average Linux terminal.
        CALLABLES_MAX = 48

        # String buffer describing these slowest callables.
        calls_sorted = StringIO()

        # Statistics harvested from this profile into this string buffer.
        calls = Stats(profile, stream=calls_sorted)

        # For readability, strip the dirnames from all pathnames in statistics
        # output, reducing these pathnames to basenames.
        calls.strip_dirs()

        # Sort all profiled callables by cumulative time (i.e., total time
        # spent in a callable including all time spent in calls to callables
        # called by that callable).
        calls.sort_stats('cumtime')

        # Write the slowest sublist of these callables to this string buffer.
        calls.print_stats(CALLABLES_MAX)

        # Sort all profiled callables by "total" time (i.e., total time spent
        # in a callable excluding all time spent in calls to callables called
        # by that callable).
        calls.sort_stats('tottime')

        # Write the slowest sublist of these callables to this string buffer.
        calls.print_stats(CALLABLES_MAX)

        # Log this string buffer.
        logs.log_info(
            'Slowest %d callables profiled by both '
            'cumulative and total time:\n%s', CALLABLES_MAX,
            calls_sorted.getvalue())

    # If the caller requested this profile be serialized to a file...
    if profile_filename is not None:
        # Log this serialization.
        logs.log_info('Writing Python-formatted profile to "%s".',
                      profile_filename)

        # Serialize this profile to this file.
        profile.dump_stats(profile_filename)

    # Return the value returned by this call.
    return return_value