[pypy-commit] benchmarks default: a few tweaks
Raemi
noreply at buildbot.pypy.org
Mon Apr 28 13:48:56 CEST 2014
Author: Remi Meier <remi.meier at inf.ethz.ch>
Branch:
Changeset: r254:de389b63b99c
Date: 2014-04-28 13:50 +0200
http://bitbucket.org/pypy/benchmarks/changeset/de389b63b99c/
Log: a few tweaks
diff --git a/multithread/btree/btree.py b/multithread/btree/btree.py
--- a/multithread/btree/btree.py
+++ b/multithread/btree/btree.py
@@ -5,8 +5,6 @@
import random
-thread_local = threading.local()
-
import bisect
@@ -195,6 +193,9 @@
def insert(self, item):
ancestors = self._path_to(item)
+ if self._present(item, ancestors):
+ return False
+
node, index = ancestors[-1]
while getattr(node, "children", None):
node = node.children[index]
@@ -202,6 +203,7 @@
ancestors.append((node, index))
node, index = ancestors.pop()
node.insert(index, item, ancestors)
+ return True
def remove(self, item):
ancestors = self._path_to(item)
@@ -301,18 +303,22 @@
self._root = self.BRANCH(self, contents=seps, children=levels[-1])
+######################################################################
+######################################################################
+######################################################################
+
OPS = [BTree.__contains__] * 98 + [BTree.insert, BTree.remove]
+ITEM_RANGE = 10000
def task(id, tree, ops):
print "start task with %s ops" % ops
r = random.Random()
r.seed(id)
- thread_local.rnd = r
for _ in xrange(ops):
op = r.choice(OPS)
- elem = r.randint(1, 10000)
+ elem = r.randint(1, ITEM_RANGE)
with atomic:
op(tree, elem)
@@ -331,11 +337,10 @@
operations = int(operations)
set_thread_pool(ThreadPool(threads))
- thread_local.rnd = random
tree = BTree(20)
for _ in xrange(1000):
- tree.insert(random.randint(1, 1000))
+ tree.insert(random.randint(1, ITEM_RANGE))
c_len = operations // threads
fs = []
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
@@ -1,6 +1,6 @@
from Queue import Queue, Empty, Full
-from threading import Thread, Condition, Lock
-import thread, atexit, sys
+from threading import Thread, Condition, Lock, local
+import thread, atexit, sys, time
try:
from __pypy__.thread import atomic, getsegmentlimit
@@ -10,6 +10,31 @@
return 1
+class TLQueue(object):
+ def __init__(self):
+ self.items = []
+ self._new_items = Condition()
+
+ def put(self, v):
+ self.items.append(v)
+ with self._new_items:
+ self._new_items.notify_all()
+
+ def get(self):
+ items = self.items
+ with atomic:
+ if items:
+ return items.pop()
+
+ while True:
+ with self._new_items:
+ with atomic:
+ if items:
+ return items.pop()
+
+ self._new_items.wait()
+
+
class Worker(Thread):
"""Thread executing tasks from a given tasks queue"""
def __init__(self, queue):
@@ -29,7 +54,7 @@
class ThreadPool(object):
def __init__(self, n_workers=None):
- self.input_queue = Queue()
+ self.input_queue = TLQueue()
if n_workers is None:
n_workers = getsegmentlimit()
self.workers = [Worker(self.input_queue) for i in range(n_workers)]
diff --git a/multithread/skiplist/skiplist.py b/multithread/skiplist/skiplist.py
--- a/multithread/skiplist/skiplist.py
+++ b/multithread/skiplist/skiplist.py
@@ -86,6 +86,7 @@
OPS = [SkipList.find] * 98 + [SkipList.insert, SkipList.remove]
+ITEM_RANGE = 10000
def task(id, slist, ops):
print "start task with %s ops" % ops
@@ -95,7 +96,7 @@
for _ in xrange(ops):
op = r.choice(OPS)
- elem = r.randint(1, 10000)
+ elem = r.randint(1, ITEM_RANGE)
with atomic:
op(slist, elem)
@@ -118,7 +119,7 @@
slist = SkipList()
for _ in xrange(1000):
- slist.insert(random.randint(1, 1000))
+ slist.insert(random.randint(1, ITEM_RANGE))
c_len = operations // threads
fs = []
More information about the pypy-commit
mailing list