Author: Remi Meier <remi.me...@inf.ethz.ch> Branch: Changeset: r255:2193a2976d5b Date: 2014-04-28 16:35 +0200 http://bitbucket.org/pypy/benchmarks/changeset/2193a2976d5b/
Log: more tweaks diff --git a/multithread/bench.py b/multithread/bench.py --- a/multithread/bench.py +++ b/multithread/bench.py @@ -34,7 +34,7 @@ def get_error(times): ts = sorted(times)[:args.k] best = float(ts[0]) - + return max((t / best) - 1.0 for t in ts) def within_error(args, times): @@ -51,6 +51,7 @@ test = import_file(os.path.basename(args.file)) times = [] + results = [] k = 1 try: while True: @@ -60,14 +61,15 @@ test_time = time.time() if args.p: - test.run(*args.more) + results.append(test.run(*args.more)) else: with nostdout(): - test.run(*args.more) + results.append(test.run(*args.more)) times.append(time.time() - test_time) if not args.q: print "took {} s".format(times[-1]) + print "returned", results[-1] if k >= args.k: if within_error(args, times): @@ -83,7 +85,9 @@ k += 1 finally: if not args.q: - print "times:", times + print "== times ==\n", "\n".join(map(str, times)) + print "== reported results ==\n", "\n".join( + map(str, filter(None, results))) if times: times = sorted(times)[:args.k] diff --git a/multithread/btree/btree.py b/multithread/btree/btree.py --- a/multithread/btree/btree.py +++ b/multithread/btree/btree.py @@ -344,16 +344,18 @@ c_len = operations // threads fs = [] + parallel_time = time.time() for i in xrange(threads): fs.append(Future(task, i, tree, c_len)) for f in fs: f() - + parallel_time = time.time() - parallel_time # print "tree:" # print tree # shutdown current pool set_thread_pool(None) + return parallel_time diff --git a/multithread/common/abstract_threading.py b/multithread/common/abstract_threading.py --- a/multithread/common/abstract_threading.py +++ b/multithread/common/abstract_threading.py @@ -10,6 +10,49 @@ return 1 +class TLQueue_concurrent(object): + def __init__(self): + my_id = thread.get_ident() + self._tl_items = {my_id : []} + self._new_items = Condition() + self._c = 0 + + def put(self, v): + # conflicts with any put() and get()s from + # the chosen queue: + c = (id(v) // 5) % len(self._tl_items) + items = self._tl_items.values()[c] + + with self._new_items: + items.append(v) + self._new_items.notify_all() + + def _get_my_items(self): + my_id = thread.get_ident() + try: + items = self._tl_items[my_id] + except KeyError: + items = [] + self._tl_items[my_id] = items + return items + + def get(self): + # tries first to get item from its + # own thread-local queue + items = self._get_my_items() + with atomic: + if items: + return items.pop() + + while True: + with self._new_items: + # steal from other queues + for its in self._tl_items.values(): + with atomic: + if its: + return its.pop() + self._new_items.wait() + class TLQueue(object): def __init__(self): self.items = [] diff --git a/multithread/mandelbrot/mandelbrot.py b/multithread/mandelbrot/mandelbrot.py --- a/multithread/mandelbrot/mandelbrot.py +++ b/multithread/mandelbrot/mandelbrot.py @@ -1,5 +1,5 @@ from common.abstract_threading import atomic, Future, set_thread_pool, ThreadPool -import sys +import sys, time def calculate(a, b, im_size, max_iter=255): @@ -11,8 +11,7 @@ real_step = (br - ar) / (width - 1) print "real/width:%s, imag/height:%s" % (real_step, imag_step) - with atomic: - result = [[0] * width for y in xrange(height)] + result = [[0] * width for y in xrange(height)] for y in xrange(height): zi = ai + y * imag_step for x in xrange(width): @@ -64,6 +63,7 @@ res = [] ai = -1.5 bi = ai + step + parallel_time = time.time() for i in xrange(threads): res.append(Future(calculate, a=(ar, ai + i * step), @@ -72,9 +72,11 @@ )) res = [f() for f in res] + parallel_time = time.time() - parallel_time set_thread_pool(None) - return merge_imgs(res) + merge_imgs(res) + return parallel_time diff --git a/multithread/raytrace/raytrace.py b/multithread/raytrace/raytrace.py --- a/multithread/raytrace/raytrace.py +++ b/multithread/raytrace/raytrace.py @@ -160,15 +160,18 @@ img = [] for x in range(w): img.append([0.0] * h) + parallel_time = time.time() for x in range(w): future_dispatcher(ths, img, x, h, cameraPos, objs, lightSource) for f in futures: print f() del futures[:] + parallel_time = time.time() - parallel_time # shutdown current pool set_thread_pool(None) + return parallel_time diff --git a/multithread/skiplist/skiplist.py b/multithread/skiplist/skiplist.py --- a/multithread/skiplist/skiplist.py +++ b/multithread/skiplist/skiplist.py @@ -123,16 +123,19 @@ c_len = operations // threads fs = [] + parallel_time = time.time() for i in xrange(threads): fs.append(Future(task, i, slist, c_len)) for f in fs: f() + parallel_time = time.time() - parallel_time # print "list:" # slist.printList() # shutdown current pool set_thread_pool(None) + return parallel_time diff --git a/multithread/threadworms/threadworms.py b/multithread/threadworms/threadworms.py --- a/multithread/threadworms/threadworms.py +++ b/multithread/threadworms/threadworms.py @@ -157,6 +157,7 @@ # Create the worm objects. worms = [] # a list that contains all the worm objects + parallel_time = time.time() for i in range(NUM_WORMS): worms.append(Worm()) for w in worms: @@ -164,6 +165,8 @@ for t in worms: t.join() + parallel_time = time.time() - parallel_time + return parallel_time _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit