[Python-checkins] r75469 - sandbox/trunk/ccbench/ccbench.py
antoine.pitrou
python-checkins at python.org
Sat Oct 17 21:53:24 CEST 2009
Author: antoine.pitrou
Date: Sat Oct 17 21:53:24 2009
New Revision: 75469
Log:
Add some alternate tasks, and bump pidigit count
Modified:
sandbox/trunk/ccbench/ccbench.py
Modified: sandbox/trunk/ccbench/ccbench.py
==============================================================================
--- sandbox/trunk/ccbench/ccbench.py (original)
+++ sandbox/trunk/ccbench/ccbench.py Sat Oct 17 21:53:24 2009
@@ -72,7 +72,26 @@
return list(_islice(pi_digits(), n))
- return calc_ndigits, (20, )
+ return calc_ndigits, (50, )
+
+def task_regex():
+ """regular expression (C)"""
+ # XXX this task gives horrendous latency results.
+ import re
+ # Taken from the `inspect` module
+ pat = re.compile(r'^(\s*def\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)', re.MULTILINE)
+ with open(__file__, "r") as f:
+ arg = f.read(200)
+
+ return pat.findall, (arg, )
+
+def task_sort():
+ """list sorting (C)"""
+ def list_sort(l):
+ l = l[::-1]
+ l.sort()
+
+ return list_sort, (list(range(10000)), )
def task_compress_zlib():
"""zlib compression (C)"""
@@ -243,6 +262,7 @@
_time = time.time
_sleep = time.sleep
def _ping():
+ t = _time()
_sendto(sock, "%r\n" % _time(), addr)
# The first ping signals the parent process that we are ready.
_ping()
@@ -272,6 +292,7 @@
results = []
threads = []
+ end_event = []
start_cond = threading.Condition()
if nthreads > 0:
# Warm up
@@ -279,14 +300,13 @@
results = []
loop = TimedLoop(func, args)
- end_event = []
ready = []
def run():
ready.append(None)
with start_cond:
start_cond.wait()
- loop(start_time, duration, end_event, do_yield=False)
+ loop(start_time, duration * 1.5, end_event, do_yield=False)
for i in range(nthreads):
threads.append(threading.Thread(target=run))
@@ -312,7 +332,9 @@
s = _recv(sock, 4096)
t = _time()
chunks.append((t, s))
-
+
+ # Tell the background threads to stop.
+ end_event.append(None)
for t in threads:
t.join()
process.wait()
@@ -340,6 +362,7 @@
n = len(results)
# We print out milliseconds
lats = [1000 * (t2 - t1) for (t1, t2) in results]
+ #print(list(map(int, lats)))
avg = sum(lats) / n
dev = (sum((x - avg) ** 2 for x in lats) / n) ** 0.5
print("CPU threads=%d: %d ms. (std dev: %d ms.)" % (nthreads, avg, dev), end="")
More information about the Python-checkins
mailing list