Index: Tools/ccbench/ccbench.py =================================================================== --- Tools/ccbench/ccbench.py (revision 79534) +++ Tools/ccbench/ccbench.py (working copy) @@ -18,6 +18,7 @@ import socket from optparse import OptionParser, SUPPRESS_HELP import platform +import math # Compatibility try: @@ -193,7 +194,7 @@ t1 = t2 -def run_throughput_test(func, args, nthreads): +def run_throughput_test(func, args, nthreads, do_yield): assert nthreads >= 1 # Warm up @@ -224,7 +225,7 @@ while not started: start_cond.wait() results.append(loop(start_time, THROUGHPUT_DURATION, - end_event, do_yield=True)) + end_event, do_yield=do_yield)) threads = [] for i in range(nthreads): @@ -245,8 +246,19 @@ t.join() return results + +def compute_balance(values): + #compute the normalized standard deviation of the results + if len(values) < 2: + return 0.0 + avg = sum(values)/len(values) + var = sum((avg-e)**2 for e in values) / (len(values)-1) + stddev = math.sqrt(var) + #normalize stddev by average + balance = stddev / avg + return balance -def run_throughput_tests(max_threads): +def run_throughput_tests(max_threads, do_yield): for task in throughput_tasks: print(task.__doc__) print() @@ -254,16 +266,17 @@ nthreads = 1 baseline_speed = None while nthreads <= max_threads: - results = run_throughput_test(func, args, nthreads) + results = run_throughput_test(func, args, nthreads, do_yield) # Taking the max duration rather than average gives pessimistic # results rather than optimistic. speed = sum(r[0] for r in results) / max(r[1] for r in results) - print("threads=%d: %d" % (nthreads, speed), end="") + balance = compute_balance([r[0] for r in results]) + print("threads=%2d: %5d" % (nthreads, speed), end="") if baseline_speed is None: - print(" iterations/s.") + print(" iterations/s. balance") baseline_speed = speed else: - print(" ( %d %%)" % (speed / baseline_speed * 100)) + print(" (%3d%%) %.4f" % (speed / baseline_speed * 100, balance)) nthreads += 1 print() @@ -546,6 +559,9 @@ parser.add_option("-n", "--num-threads", action="store", type="int", dest="nthreads", default=4, help="max number of threads in tests") + parser.add_option("-y", "--no-yield", + action="store_false", dest="do_yield", default=True, + help="don't force threads to yield") # Hidden option to run the pinging and bandwidth clients parser.add_option("", "--latclient", @@ -593,7 +609,7 @@ if options.throughput: print("--- Throughput ---") print() - run_throughput_tests(options.nthreads) + run_throughput_tests(options.nthreads, options.do_yield) if options.latency: print("--- Latency ---")