コード例 #1
0
ファイル: bm_pickle.py プロジェクト: bennn/retic_performance
def test_unpickle_list(loops, timer, pickle, options):
    pickled_list = pickle.dumps(LIST, options.protocol)

    # Warm-up runs.
    pickle.loads(pickled_list)
    pickle.loads(pickled_list)

    loops = loops // 5  # Scale to compensate for the workload.
    times = []
    for _ in xrange(options.num_runs):
        t0 = timer()
        for _ in xrange(loops):
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #2
0
ファイル: bm_hexiom2.py プロジェクト: bennn/retic_performance
def print_pos(pos, output):
    hex = pos.hex
    done = pos.done
    size = hex.size
    for y in xrange(size):
        print(u_lit(" ") * (size - y - 1), end=u_lit(""), file=output)
        for x in xrange(size + y):
            pos2 = (x, y)
            id = hex.get_by_pos(pos2).id
            if done.already_done(id):
                c = unicode(done[id][0]) if done[id][0] != EMPTY else u_lit(".")
            else:
                c = u_lit("?")
            print(u_lit("%s ") % c, end=u_lit(""), file=output)
        print(end=u_lit("\n"), file=output)
    for y in xrange(1, size):
        print(u_lit(" ") * y, end=u_lit(""), file=output)
        for x in xrange(y, size * 2 - 1):
            ry = size + y - 1
            pos2 = (x, ry)
            id = hex.get_by_pos(pos2).id
            if done.already_done(id):
                c = unicode(done[id][0]) if done[id][0] != EMPTY else u_lit(".")
            else:
                c = u_lit("?")
            print(u_lit("%s ") % c, end=u_lit(""), file=output)
        print(end=u_lit("\n"), file=output)
コード例 #3
0
def test_unpickle_list(loops, timer, pickle, options):
    pickled_list = pickle.dumps(LIST, options.protocol)

    # Warm-up runs.
    pickle.loads(pickled_list)
    pickle.loads(pickled_list)

    loops = loops // 5  # Scale to compensate for the workload.
    times = []
    for _ in xrange(options.num_runs):
        t0 = timer()
        for _ in xrange(loops):
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
            pickle.loads(pickled_list)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #4
0
def print_pos(pos, output):
    hex = pos.hex
    done = pos.done
    size = hex.size
    for y in xrange(size):
        print(u_lit(" ") * (size - y - 1), end=u_lit(""), file=output)
        for x in xrange(size + y):
            pos2 = (x, y)
            id = hex.get_by_pos(pos2).id
            if done.already_done(id):
                c = unicode(
                    done[id][0]) if done[id][0] != EMPTY else u_lit(".")
            else:
                c = u_lit("?")
            print(u_lit("%s ") % c, end=u_lit(""), file=output)
        print(end=u_lit("\n"), file=output)
    for y in xrange(1, size):
        print(u_lit(" ") * y, end=u_lit(""), file=output)
        for x in xrange(y, size * 2 - 1):
            ry = size + y - 1
            pos2 = (x, ry)
            id = hex.get_by_pos(pos2).id
            if done.already_done(id):
                c = unicode(
                    done[id][0]) if done[id][0] != EMPTY else u_lit(".")
            else:
                c = u_lit("?")
            print(u_lit("%s ") % c, end=u_lit(""), file=output)
        print(end=u_lit("\n"), file=output)
コード例 #5
0
def print_board(board, w=w, h=h):
    for y in xrange(h):
        for x in xrange(w):
            print(board[x + y * w])
        print('')
        if y % 2 == 0:
            print('')
    print()
コード例 #6
0
def print_board(board, w=w, h=h):
    for y in xrange(h):
        for x in xrange(w):
            print(board[x + y * w])
        print('')
        if y % 2 == 0:
            print('')
    print()
コード例 #7
0
def get_footprints(board, cti, pieces):
    fps = [[[] for p in xrange(len(pieces))] for ci in xrange(len(board))]
    for c in board:
        for pi, p in enumerate(pieces):
            for pp in p:
                fp = frozenset([cti[c + o] for o in pp if (c + o) in cti])
                if len(fp) == 5:
                    fps[min(fp)][pi].append(fp)
    return fps
コード例 #8
0
def get_footprints(board, cti, pieces):
    fps = [[[] for p in xrange(len(pieces))] for ci in xrange(len(board))]
    for c in board:
        for pi, p in enumerate(pieces):
            for pp in p:
                fp = frozenset([cti[c + o] for o in pp if (c + o) in cti])
                if len(fp) == 5:
                    fps[min(fp)][pi].append(fp)
    return fps
コード例 #9
0
def get_footprints(board:List(float), cti:Dict(float,int), pieces:List(List(List(float))))-> \
    List(List(List(Set(List(int))))):
    fps = [[[] for p in xrange(len(pieces))] for ci in xrange(len(board))]
    for c in board:
        for pi, p in enumerate(pieces):
            for pp in p:
                fp = frozenset([cti[c + o] for o in pp if (c + o) in cti])
                if len(fp) == 5:
                    fps[min(fp)][pi].append(fp)
    return fps
コード例 #10
0
ファイル: bm_json_v2.py プロジェクト: bennn/retic_performance
def main(n, timer):
    l = []
    for i in xrange(n):
        t0 = timer()
        for case in cases:
            data, count = globals()[case]
            for i in xrange(count):
                json.dumps(data)
        l.append(timer() - t0)
    return l
コード例 #11
0
 def main():
     client = AsyncHTTPClient()
     for i in xrange(count):
         t0 = timer()
         futures = [client.fetch(url) for j in xrange(CONCURRENCY)]
         for fut in futures:
             resp = yield fut
             buf = resp.buffer
             buf.seek(0, 2)
             assert buf.tell() == len(CHUNK) * NCHUNKS
         t1 = timer()
         times.append(t1 - t0)
コード例 #12
0
def test_iterative_count(iterations, timer, num_threads):
    # Warm up.
    count(1000)

    times = []
    for _ in xrange(iterations):
        t0 = timer()
        for _ in xrange(num_threads):
            count()
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #13
0
 def main():
     client = AsyncHTTPClient()
     for i in xrange(count):
         t0 = timer()
         futures = [client.fetch(url) for j in xrange(CONCURRENCY)]
         for fut in futures:
             resp = yield fut
             buf = resp.buffer
             buf.seek(0, 2)
             assert buf.tell() == len(CHUNK) * NCHUNKS
         t1 = timer()
         times.append(t1 - t0)
コード例 #14
0
def test_iterative_count(iterations, timer, num_threads):
    # Warm up.
    count(1000)

    times = []
    for _ in xrange(iterations):
        t0 = timer()
        for _ in xrange(num_threads):
            count()
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #15
0
def main(n, timer):
    times = []
    for i in xrange(n):
        t0 = timer()
        free = frozenset(xrange(len(board)))
        curr_board = [-1] * len(board)
        pieces_left = list(range(len(pieces)))
        solutions = []
        solve(SOLVE_ARG, 0, free, curr_board, pieces_left, solutions)
        #print len(solutions),  'solutions found\n'
        #for i in (0, -1): print_board(solutions[i])
        tk = timer()
        times.append(tk - t0)
    return times
コード例 #16
0
def test_mako(count, timer):
    table = [xrange(150) for _ in xrange(150)]

    # Warm up Mako.
    MAKO_TMPL.render(table=table)
    MAKO_TMPL.render(table=table)

    times = []
    for _ in xrange(count):
        t0 = timer()
        MAKO_TMPL.render(table=table)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #17
0
ファイル: bm_mako.py プロジェクト: bennn/retic_performance
def test_mako(count, timer):
    table = [xrange(150) for _ in xrange(150)]

    # Warm up Mako.
    MAKO_TMPL.render(table = table)
    MAKO_TMPL.render(table = table)

    times = []
    for _ in xrange(count):
        t0 = timer()
        MAKO_TMPL.render(table = table)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #18
0
def main(n, timer):
    times = []
    for i in xrange(n):
        t0 = timer()
        free = frozenset(xrange(len(board)))
        curr_board = [-1] * len(board)
        pieces_left = list(range(len(pieces)))
        solutions = []
        solve(SOLVE_ARG, 0, free, curr_board, pieces_left, solutions)
        #print len(solutions),  'solutions found\n'
        #for i in (0, -1): print_board(solutions[i])
        tk = timer()
        times.append(tk - t0)
    return times
コード例 #19
0
def test_threaded_count(iterations, timer, num_threads):
    # Warm up.
    count(1000)

    times = []
    for _ in xrange(iterations):
        threads = [threading.Thread(target=count) for _ in xrange(num_threads)]
        t0 = timer()
        for thread in threads:
            thread.start()
        for thread in threads:
            thread.join()
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #20
0
def test_django(count, timer):
    table = [xrange(150) for _ in xrange(150)]
    context = Context({"table": table})

    # Warm up Django.
    DJANGO_TMPL.render(context)
    DJANGO_TMPL.render(context)

    times = []
    for _ in xrange(count):
        t0 = timer()
        data = DJANGO_TMPL.render(context)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #21
0
def test_django(count, timer):
    table = [xrange(150) for _ in xrange(150)]
    context = Context({"table": table})

    # Warm up Django.
    DJANGO_TMPL.render(context)
    DJANGO_TMPL.render(context)

    times = []
    for _ in xrange(count):
        t0 = timer()
        data = DJANGO_TMPL.render(context)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #22
0
def test_threaded_count(iterations, timer, num_threads):
    # Warm up.
    count(1000)

    times = []
    for _ in xrange(iterations):
        threads = [threading.Thread(target=count) for _ in xrange(num_threads)]
        t0 = timer()
        for thread in threads:
            thread.start()
        for thread in threads:
            thread.join()
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #23
0
ファイル: landmines_test.py プロジェクト: woozyking/techies
    def test_qsize(self):
        if sys.version_info[:2] > (2, 6):
            super(UniQueueTest, self).test_qsize()
        else:
            QueueTest.test_qsize(self)

        self.obj.clear()

        s = random.randint(1, 32)
        n = random.randint(2, 5)
        for _ in xrange(n):
            for i in xrange(s):
                self.obj.put(i)

        self.assertEqual(self.obj.qsize(), s)
コード例 #24
0
 def remove_unfixed(self, v):
     changed = False
     for i in xrange(self.count):
         if not self.already_done(i):
             if self.remove(i, v):
                 changed = True
     return changed
コード例 #25
0
def benchmark(n):
    points = [None] * n
    for i in xrange(n):
        points[i] = Point(i)
    for p in points:
        p.normalize()
    return maximize(points)
コード例 #26
0
def run_etree_benchmark(iterations, timer, etree, bench_func):
    times = []

    xml_root = build_xml_tree(etree)
    xml_data = etree.tostring(xml_root)

    # not using NamedTemporaryFile() here as re-opening it is not portable
    tf, file_path = tempfile.mkstemp()
    try:
        etree.ElementTree(xml_root).write(file_path)

        # warm up
        bench_func(etree, file_path, xml_data, xml_root)
        bench_func(etree, file_path, xml_data, xml_root)

        for _ in xrange(iterations):
            t0 = timer()
            bench_func(etree, file_path, xml_data, xml_root)
            t1 = timer()
            times.append(t1 - t0)
    finally:
        try:
            os.close(tf)
        except EnvironmentError:
            pass
        try:
            os.unlink(file_path)
        except EnvironmentError:
            pass

    return times
コード例 #27
0
def test_calls(iterations, timer):
    times = []
    f = Foo()
    if hasattr(f, '__dict__'):
        raise Exception("f has a __dict__ attribute!")
    for _ in xrange(iterations):
        t0 = timer()
        # 20 calls
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #28
0
def test_calls(iterations, timer):
    times = []
    f = Foo()
    if hasattr(f, '__dict__'):
        raise Exception("f has a __dict__ attribute!")
    for _ in xrange(iterations):
        t0 = timer()
        # 20 calls
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #29
0
def test_calls(iterations, timer):
    times = []
    a = Foo()
    b = Bar()
    c = Baz()
    for _ in xrange(iterations):
        t0 = timer()
        # 18 calls
        a.foo(b, c)
        b.foo(c, a)
        c.foo(a, b)
        a.foo(b, c)
        b.foo(c, a)
        c.foo(a, b)
        a.foo(b, c)
        b.foo(c, a)
        c.foo(a, b)
        a.foo(b, c)
        b.foo(c, a)
        c.foo(a, b)
        a.foo(b, c)
        b.foo(c, a)
        c.foo(a, b)
        a.foo(b, c)
        b.foo(c, a)
        c.foo(a, b)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #30
0
def test_calls(iterations, timer):
    times = []
    f = Foo()
    for _ in xrange(iterations):
        t0 = timer()
        # 20 calls
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        f.foo(1, 2, 3, 4)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #31
0
ファイル: bm_hexiom2.py プロジェクト: bennn/retic_performance
 def remove_unfixed(self, v):
     changed = False
     for i in xrange(self.count):
         if not self.already_done(i):
             if self.remove(i, v):
                 changed = True
     return changed
コード例 #32
0
def test_calls(iterations, timer):
    times = []
    a = Foo()
    b = Bar()
    c = Baz()
    for _ in xrange(iterations):
        t0 = timer()
        # 18 calls
        a.foo(b, c)
        b.foo(c, a)
        c.foo(a, b)
        a.foo(b, c)
        b.foo(c, a)
        c.foo(a, b)
        a.foo(b, c)
        b.foo(c, a)
        c.foo(a, b)
        a.foo(b, c)
        b.foo(c, a)
        c.foo(a, b)
        a.foo(b, c)
        b.foo(c, a)
        c.foo(a, b)
        a.foo(b, c)
        b.foo(c, a)
        c.foo(a, b)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #33
0
def run_etree_benchmark(iterations, timer, etree, bench_func):
    times = []

    xml_root = build_xml_tree(etree)
    xml_data = etree.tostring(xml_root)

    # not using NamedTemporaryFile() here as re-opening it is not portable
    tf, file_path = tempfile.mkstemp()
    try:
        etree.ElementTree(xml_root).write(file_path)

        # warm up
        bench_func(etree, file_path, xml_data, xml_root)
        bench_func(etree, file_path, xml_data, xml_root)

        for _ in xrange(iterations):
            t0 = timer()
            bench_func(etree, file_path, xml_data, xml_root)
            t1 = timer()
            times.append(t1 - t0)
    finally:
        try:
            os.close(tf)
        except EnvironmentError:
            pass
        try:
            os.unlink(file_path)
        except EnvironmentError:
            pass

    return times
コード例 #34
0
ファイル: richards.py プロジェクト: bennn/retic_performance
    def run(self, iterations:int)->bool:
        for i in xrange(iterations):
            taskWorkArea.holdCount = 0
            taskWorkArea.qpktCount = 0

            IdleTask(I_IDLE, 1, 10000, TaskState().running(), IdleTaskRec())

            wkq = Packet(None, 0, K_WORK)
            wkq = Packet(wkq , 0, K_WORK)
            WorkTask(I_WORK, 1000, wkq, TaskState().waitingWithPacket(), WorkerTaskRec())

            wkq = Packet(None, I_DEVA, K_DEV)
            wkq = Packet(wkq , I_DEVA, K_DEV)
            wkq = Packet(wkq , I_DEVA, K_DEV)
            HandlerTask(I_HANDLERA, 2000, wkq, TaskState().waitingWithPacket(), HandlerTaskRec())

            wkq = Packet(None, I_DEVB, K_DEV)
            wkq = Packet(wkq , I_DEVB, K_DEV)
            wkq = Packet(wkq , I_DEVB, K_DEV)
            HandlerTask(I_HANDLERB, 3000, wkq, TaskState().waitingWithPacket(), HandlerTaskRec())

            wkq = None;
            DeviceTask(I_DEVA, 4000, wkq, TaskState().waiting(), DeviceTaskRec());
            DeviceTask(I_DEVB, 5000, wkq, TaskState().waiting(), DeviceTaskRec());
            
            schedule()

            if taskWorkArea.holdCount == 9297 and taskWorkArea.qpktCount == 23246:
                pass
            else:
                return False

        return True
コード例 #35
0
def test_calls(iterations, timer):
    times = []
    for _ in xrange(iterations):
        t0 = timer()
        # 20 calls
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        foo(1, 2, 3, 4)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #36
0
 def next_cell_max_choice(self):
     maxlen = 1
     maxi = -1
     for i in xrange(self.count):
         if maxlen < len(self.cells[i]):
             maxlen = len(self.cells[i])
             maxi = i
     return maxi
コード例 #37
0
ファイル: bm_hexiom2.py プロジェクト: bennn/retic_performance
 def next_cell_max_choice(self):
     maxlen = 1
     maxi = -1
     for i in xrange(self.count):
         if maxlen < len(self.cells[i]):
             maxlen = len(self.cells[i])
             maxi = i
     return maxi
コード例 #38
0
ファイル: landmines_test.py プロジェクト: woozyking/techies
    def test_len(self):
        self.assertEqual(len(self.obj), 0)

        s = random.randint(1, 32)
        for i in xrange(s):
            self.obj.put(i)

        self.assertEqual(len(self.obj), s)
コード例 #39
0
ファイル: landmines_test.py プロジェクト: woozyking/techies
    def test_qsize(self):
        self.assertEqual(self.obj.qsize(), 0)

        s = random.randint(1, 32)
        for i in xrange(s):
            self.obj.put(i)

        self.assertEqual(self.obj.qsize(), s)
コード例 #40
0
ファイル: bm_hexiom2.py プロジェクト: bennn/retic_performance
def read_file(file):
    lines = [line.strip("\r\n") for line in file.splitlines()]
    size = int(lines[0])
    hex = Hex(size)
    linei = 1
    tiles = 8 * [0]
    done = Done(hex.count)
    for y in xrange(size):
        line = lines[linei][size - y - 1:]
        p = 0
        for x in xrange(size + y):
            tile = line[p:p + 2];
            p += 2
            if tile[1] == ".":
                inctile = EMPTY
            else:
                inctile = int(tile)
            tiles[inctile] += 1
            # Look for locked tiles    
            if tile[0] == "+":
                print("Adding locked tile: %d at pos %d, %d, id=%d" %
                      (inctile, x, y, hex.get_by_pos((x, y)).id))
                done.set_done(hex.get_by_pos((x, y)).id, inctile)
            
        linei += 1
    for y in xrange(1, size):
        ry = size - 1 + y
        line = lines[linei][y:]
        p = 0
        for x in xrange(y, size * 2 - 1):
            tile = line[p:p + 2];
            p += 2
            if tile[1] == ".":
                inctile = EMPTY
            else:
                inctile = int(tile)
            tiles[inctile] += 1
            # Look for locked tiles    
            if tile[0] == "+":
                print("Adding locked tile: %d at pos %d, %d, id=%d" %
                      (inctile, x, ry, hex.get_by_pos((x, ry)).id))
                done.set_done(hex.get_by_pos((x, ry)).id, inctile)
        linei += 1
    hex.link_nodes()
    done.filter_tiles(tiles)
    return Pos(hex, tiles, done)
コード例 #41
0
ファイル: bm_nbody.py プロジェクト: bennn/retic_performance
def combinations(l:List((List(float), List(float), float)))->List((List((List(float), List(float), float)), (List(float), List(float), float))): #<- ret ty temp
    """Pure-Python implementation of itertools.combinations(l, 2)."""
    result = []
    for x in xrange(len(l) - 1):
        ls = l[x+1:]
        for y in ls:
            result.append((l[x],y))
    return result
コード例 #42
0
def main(n, timer):
    times = []
    for i in xrange(n):
        t0 = timer()
        fannkuch(DEFAULT_ARG)
        tk = timer()
        times.append(tk - t0)
    return times
コード例 #43
0
 def next_cell_min_choice(self):
     minlen = 10
     mini = -1
     for i in xrange(self.count):
         if 1 < len(self.cells[i]) < minlen:
             minlen = len(self.cells[i])
             mini = i
     return mini
コード例 #44
0
ファイル: landmines_test.py プロジェクト: woozyking/techies
    def test_put(self):
        a = random.randint(1, 32)
        n = random.randint(1, 5)
        for _ in xrange(n):
            self.obj.put(a)

        v = self.obj.get()
        self.assertEqual(v, (unicode(a), n))
コード例 #45
0
def read_file(file):
    lines = [line.strip("\r\n") for line in file.splitlines()]
    size = int(lines[0])
    hex = Hex(size)
    linei = 1
    tiles = 8 * [0]
    done = Done(hex.count)
    for y in xrange(size):
        line = lines[linei][size - y - 1:]
        p = 0
        for x in xrange(size + y):
            tile = line[p:p + 2]
            p += 2
            if tile[1] == ".":
                inctile = EMPTY
            else:
                inctile = int(tile)
            tiles[inctile] += 1
            # Look for locked tiles
            if tile[0] == "+":
                print("Adding locked tile: %d at pos %d, %d, id=%d" %
                      (inctile, x, y, hex.get_by_pos((x, y)).id))
                done.set_done(hex.get_by_pos((x, y)).id, inctile)

        linei += 1
    for y in xrange(1, size):
        ry = size - 1 + y
        line = lines[linei][y:]
        p = 0
        for x in xrange(y, size * 2 - 1):
            tile = line[p:p + 2]
            p += 2
            if tile[1] == ".":
                inctile = EMPTY
            else:
                inctile = int(tile)
            tiles[inctile] += 1
            # Look for locked tiles
            if tile[0] == "+":
                print("Adding locked tile: %d at pos %d, %d, id=%d" %
                      (inctile, x, ry, hex.get_by_pos((x, ry)).id))
                done.set_done(hex.get_by_pos((x, ry)).id, inctile)
        linei += 1
    hex.link_nodes()
    done.filter_tiles(tiles)
    return Pos(hex, tiles, done)
コード例 #46
0
ファイル: bm_hexiom2.py プロジェクト: bennn/retic_performance
 def next_cell_min_choice(self):
     minlen = 10
     mini = -1
     for i in xrange(self.count):
         if 1 < len(self.cells[i]) < minlen:
             minlen = len(self.cells[i])
             mini = i
     return mini
コード例 #47
0
ファイル: bm_nbody.py プロジェクト: bennn/retic_performance
def combinations(l):
    """Pure-Python implementation of itertools.combinations(l, 2)."""
    result = []
    for x in xrange(len(l) - 1):
        ls = l[x+1:]
        for y in ls:
            result.append((l[x],y))
    return result
コード例 #48
0
def main(n, timer):
    times = []
    for i in xrange(n):
        t0 = timer()
        fannkuch(DEFAULT_ARG)
        tk = timer()
        times.append(tk - t0)
    return times
コード例 #49
0
ファイル: bm_pickle.py プロジェクト: bennn/retic_performance
def test_pickle_dict(loops, timer, pickle, options):
    # Warm-up runs.
    pickle.dumps(MICRO_DICT, options.protocol)
    pickle.dumps(MICRO_DICT, options.protocol)

    loops = max(1, loops // 10)
    times = []
    for _ in xrange(options.num_runs):
        t0 = timer()
        for _ in xrange(loops):
            pickle.dumps(MICRO_DICT, options.protocol)
            pickle.dumps(MICRO_DICT, options.protocol)
            pickle.dumps(MICRO_DICT, options.protocol)
            pickle.dumps(MICRO_DICT, options.protocol)
            pickle.dumps(MICRO_DICT, options.protocol)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #50
0
def get_puzzle(w=w, h=h):
    board = [E*x + S*y + (y%2) for y in xrange(h) for x in xrange(w)]
    cti = dict((board[i], i) for i in xrange(len(board)))

    idos = [[E, E, E, SE],         # incremental direction offsets
            [SE, SW, W, SW],
            [W, W, SW, SE],
            [E, E, SW, SE],
            [NW, W, NW, SE, SW],
            [E, E, NE, W],
            [NW, NE, NE, W],
            [NE, SE, E, NE],
            [SE, SE, E, SE],
            [E, NW, NW, NW]]

    perms = (permute(p, idos[3]) for p in idos)    # restrict piece 4
    pieces = [[convert(pp) for pp in p] for p in perms]
    return (board, cti, pieces)
コード例 #51
0
def permute(ido, r_ido, rotate=rotate, flip=flip):
    ps = [ido]
    for r in xrange(dir_no - 1):
        ps.append(rotate(ps[-1]))
        if ido == r_ido:  # C2-symmetry
            ps = ps[0:dir_no // 2]
    for pp in ps[:]:
        ps.append(flip(pp))
    return ps
コード例 #52
0
def main(n, timer):
    times = []
    for i in xrange(n):
        t0 = timer()
        u = [1] * DEFAULT_N

        for dummy in xrange(10):
            v = eval_AtA_times_u(u)
            u = eval_AtA_times_u(v)

        vBv = vv = 0

        for ue, ve in izip(u, v):
            vBv += ue * ve
            vv  += ve * ve
        tk = timer()
        times.append(tk - t0)
    return times
コード例 #53
0
def test_pickle_dict(loops, timer, pickle, options):
    # Warm-up runs.
    pickle.dumps(MICRO_DICT, options.protocol)
    pickle.dumps(MICRO_DICT, options.protocol)

    loops = max(1, loops // 10)
    times = []
    for _ in xrange(options.num_runs):
        t0 = timer()
        for _ in xrange(loops):
            pickle.dumps(MICRO_DICT, options.protocol)
            pickle.dumps(MICRO_DICT, options.protocol)
            pickle.dumps(MICRO_DICT, options.protocol)
            pickle.dumps(MICRO_DICT, options.protocol)
            pickle.dumps(MICRO_DICT, options.protocol)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #54
0
 def next_cell_highest_value(self):
     maxval = -1
     maxi = -1
     for i in xrange(self.count):
         if (not self.already_done(i)):
             maxvali = max(k for k in self.cells[i] if k != EMPTY)
             if maxval < maxvali:
                 maxval = maxvali
                 maxi = i
     return maxi
コード例 #55
0
def main(n, timer):
    # only run 1/25th of the requested number of iterations.
    # with the default n=50 from runner.py, this means twice.
    l = []
    for i in xrange(n):
        t0 = timer()
        run_level36()
        time_elapsed = timer() - t0
        l.append(time_elapsed)
    return l
コード例 #56
0
def test_simple_output(iterations, timer, logger):
    times = []
    m = MESSAGE
    for _ in xrange(iterations):
        t0 = timer()
        for _ in xrange(1000):
            logger.warn(m)
            logger.warn(m)
            logger.warn(m)
            logger.warn(m)
            logger.warn(m)
            logger.warn(m)
            logger.warn(m)
            logger.warn(m)
            logger.warn(m)
            logger.warn(m)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #57
0
def main(arg, timer):
    # XXX warmup

    times = []
    for i in xrange(arg):
        t0 = timer()
        o = benchmark(POINTS)
        tk = timer()
        times.append(tk - t0)
    return times
コード例 #58
0
def test_formatted_output(iterations, timer, logger):
    times = []
    f = FORMAT
    m = MESSAGE
    for _ in xrange(iterations):
        t0 = timer()
        for _ in xrange(1000):
            logger.warn(f, m)
            logger.warn(f, m)
            logger.warn(f, m)
            logger.warn(f, m)
            logger.warn(f, m)
            logger.warn(f, m)
            logger.warn(f, m)
            logger.warn(f, m)
            logger.warn(f, m)
            logger.warn(f, m)
        t1 = timer()
        times.append(t1 - t0)
    return times
コード例 #59
0
def get_puzzle(w=w, h=h):
    board = [E * x + S * y + (y % 2) for y in xrange(h) for x in xrange(w)]
    cti = dict((board[i], i) for i in xrange(len(board)))

    idos = [
        [E, E, E, SE],  # incremental direction offsets
        [SE, SW, W, SW],
        [W, W, SW, SE],
        [E, E, SW, SE],
        [NW, W, NW, SE, SW],
        [E, E, NE, W],
        [NW, NE, NE, W],
        [NE, SE, E, NE],
        [SE, SE, E, SE],
        [E, NW, NW, NW]
    ]

    perms = (permute(p, idos[3]) for p in idos)  # restrict piece 4
    pieces = [[convert(pp) for pp in p] for p in perms]
    return (board, cti, pieces)
コード例 #60
0
def test_n_queens(iterations, timer):
    # Warm-up runs.
    list(n_queens(8))
    list(n_queens(8))

    times = []
    for _ in xrange(iterations):
        t0 = timer()
        list(n_queens(8))
        t1 = timer()
        times.append(t1 - t0)
    return times