Example #1
0
then in objects.base the getRange method was optimized.
It still is the main bottleneck,
but there seems to be no potential for further optimization.

Now you should modify/copy this file,
to profile your AI source code.

In some tournaments, there is a penalty for computation cost."""

from src.Wesen.loader import Loader
from cProfile import Profile
from time import perf_counter
# only in python3.3
from pstats import Stats
import sys

print("You can supply an alternative config file on the command-line")
print("You should stop Wesen by Ctrl+C to finish profiling")

sys.argv.append('--disablegui')
pr = Profile(perf_counter)
pr.run('Loader()')
pr.dump_stats('profile.stats')
# you may explore profile.stats with the pstats browser.

stats = Stats(pr)

stats.sort_stats('tottime')
# stats.print_stats('Wesen/sources',10)
stats.print_stats('Wesen/', 10)
Example #2
0
import shutil
import os


if __name__ == '__main__':
    logging.getLogger().setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    logformat = '%(asctime)s|%(levelname)s|%(name)s|%(message)s'
    ch.setFormatter(logging.Formatter(logformat))
    logging.getLogger().addHandler(ch)
    logger = logging.getLogger('run')
    logger.info('Starting profiling')

    def run_somecommand():
        from ppci.api import construct
        print(construct)
        construct('../examples/linux64/fib/build.xml')

    p = Profile()
    s = p.run('run_somecommand()')
    stats = pstats.Stats(p)
    stats.dump_stats('results.cprofile')
    stats.sort_stats('cumtime')

    logger.info('Done profiling')

    # Convert result profile to kcachegrind format:
    if shutil.which('pyprof2calltree'):
        os.system('pyprof2calltree -i results.cprofile')
Example #3
0
    cx, cy = data.shape[1] // 2, data.shape[0] // 2
    idx = 0
    radii = list()
    for idx in range(60, 70):
        frame = (convert_image(_smooth(data[idx], 1)))
        y_size, x_size = frame.shape
        points = StarBurst(cx + cy * 1j, 30).detect(frame)
        result = fit(Conic, EllipseNormalizer(), points)
        min_result = refine_pupil(frame, result)
        x, y, a, b, Θ = min_result  # conic2ellipse(result.coef)
        radii.append(np.sqrt(a * b))
        cosΘ, sinΘ = np.cos(Θ), np.sin(Θ)
        x_mesh, y_mesh = np.meshgrid(np.arange(x_size), np.arange(y_size))
        mask = (((x_mesh - x) * cosΘ - (y_mesh - y) * sinΘ) / a) ** 2\
            + (((x_mesh - x) * sinΘ + (y_mesh - y) * cosΘ) / b) ** 2 < 1
        with MplFigure(f"sample_frame_{idx}.png", (6, 4)) as ax:
            ax.imshow(frame / 2 + mask * 128)
            ax.scatter(points.real, points.imag)
    return radii


##
from cProfile import Profile

profile = Profile()
profile.run("test_detect(data)")
profile.dump_stats("stats.prof")
print('done')
##
radii = test_detect(data)
Example #4
0
then in objects.base the getRange method was optimized.
It still is the main bottleneck,
but there seems to be no potential for further optimization.

Now you should modify/copy this file,
to profile your AI source code.

In some tournaments, there is a penalty for computation cost."""

from src.Wesen.loader import Loader
from cProfile import Profile
from time import perf_counter
# only in python3.3
from pstats import Stats
import sys

print("You can supply an alternative config file on the command-line")
print("You should stop Wesen by Ctrl+C to finish profiling")

sys.argv.append('--disablegui')
pr = Profile(perf_counter)
pr.run('Loader()')
pr.dump_stats('profile.stats')
# you may explore profile.stats with the pstats browser.

stats = Stats(pr)

stats.sort_stats('tottime')
# stats.print_stats('Wesen/sources',10)
stats.print_stats('Wesen/', 10)
Example #5
0
            except IndexError:
                pass
            return side*side

        max_square = 0
        for row_i, row in enumerate(matrix):
            if '1' in row:
                for column_i, column in enumerate(row):
                    if column == '1':
                        max_square = max(max_square,tell_square(row_i,column_i))
        return max_square
profile = Profile()
s = Solution()
a = [["0","0","0","1","0","1","1","1"],["0","1","1","0","0","1","0","1"],["1","0","1","1","1","1","0","1"],["0","0","0","1","0","0","0","0"],["0","0","1","0","0","0","1","0"],["1","1","1","0","0","1","1","1"],["1","0","0","1","1","0","0","1"],["0","1","0","0","1","1","0","0"],["1","0","0","1","0","0","0","0"]]

profile.run('s.maximalSquare(a)')
stats = Stats(profile)
stats.strip_dirs()
stats.sort_stats('cumulative')
stats.print_stats()

#Excellent code
# class Solution(object):
#     def maximalSquare(self, matrix):
#         """
#         :type matrix: List[List[str]]
#         :rtype: int
#         """
#         if not matrix:
#             return 0
#         m = len(matrix);n = len(matrix[0])
Example #6
0
    times = []
    worlds_data = []
    game_count = 0
    while game_count < num_games:
        (W, goal_list, init_list, env_init_list) = random_world(size=(height, width),
                                                                wall_density=bdensity,
                                                                num_goals=2,
                                                                num_env=num_env)

        print "Nominal world:"
        print pretty_world(W, goal_list=goal_list, init_list=init_list,
                           env_init_list=env_init_list)

        print "Trying to solve..."
        nsprof = Profile()
        nsprof.run("aut = gen_navobs_soln(init_list=init_list, goal_list=goal_list, W=W, num_obs=len(env_init_list), env_init_list=env_init_list, restrict_radius=1)")
        if aut is None:
            print "Nominal spec not feasible."
            print "#"*60
            continue
        
        print "Resulting solution automaton M has %d nodes." % aut.size()
        aut.trimDeadStates()
        print "After trimming dead nodes, M has size %d" % aut.size()

        ind = -1
        while not hasattr(nsprof.getstats()[ind].code, "co_name") or (nsprof.getstats()[ind].code.co_name != "gen_navobs_soln"):
            ind -= 1
        nom_time = nsprof.getstats()[ind].totaltime

        aut.writeDotFileCoord("tempsyn-ORIG.dot")
Example #7
0
    po = powerset(n)
    print("make powerset")
    l = 2**n-2
    print("count topology")
    core = 10
    t=0
    output = Queue()
    procs= [0]*core
    rancore = range(core)
    for i in rancore:
        procs[i] = Process(target=proce,args=(i,core,l,po,output))
    for i in rancore:
        procs[i].start()
        print('process %d start'%i)
    #process
    for i in rancore:
        procs[i].join()
        t += output.get()
        print('process %d end' % i)
    output.close()
    return t

if __name__=="__main__":
    profile = Profile()
    n = int(input('input cardinal number of topology: '))
    profile.run('checkdimen(n)')
    stats = Stats(profile)
    stats.strip_dirs()
    stats.sort_stats('cumulative')
    stats.print_stats()