aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMichael Hope <michael.hope@linaro.org>2011-03-17 09:53:45 +1300
committerMichael Hope <michael.hope@linaro.org>2011-03-17 09:53:45 +1300
commit35807ebfe4fc2bfb6c5ae2430916c5161747580a (patch)
tree846b3dea15150d33b031fe1dfb68c225e9e555cd /scripts
parent06808eaad6d7681474886cbdb243fe416018c1a3 (diff)
Added a script to run all of the benchmarks, and a routine to plot the results.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bench-all.sh20
-rw-r--r--scripts/plot.py116
2 files changed, 136 insertions, 0 deletions
diff --git a/scripts/bench-all.sh b/scripts/bench-all.sh
new file mode 100644
index 0000000..d54afa3
--- /dev/null
+++ b/scripts/bench-all.sh
@@ -0,0 +1,20 @@
+#!/bin/bash
+#
+# Benchmark all variants of all functions
+
+# memcpy: 9.905206 s for 10000000 calls to memcpy of 3328 bytes. ~3204.202 MB/s
+# To run for 10 s, transfer 30 GB. So loops is 30e9 / size
+for t in memcpy memset memchr strcpy strlen strcmp strchr bounce; do
+ for variant in try-all try-bionic try-csl try-glibc try-newlib try-none try-plain; do
+ #for size in 256 512 1024 2048 4096 8192 16384 $(seq 4 4 128); do
+ for size in $(seq 4 4 128); do
+ if [[ $size -le 128 ]]; then
+ loops=$(( 250000000 - 1000000 * $size ))
+ else
+ loops=$(( 30000000000 / $size ))
+ fi
+ ./$variant -t $t -c $size -l $loops
+ done
+ done
+done
+250000000 - 1000000*size
diff --git a/scripts/plot.py b/scripts/plot.py
new file mode 100644
index 0000000..eb3c8e7
--- /dev/null
+++ b/scripts/plot.py
@@ -0,0 +1,116 @@
+"""Plot the results for each test. Spits out a set of images into the
+current directory.
+"""
+
+import fileinput
+import collections
+import pprint
+
+import pylab
+
+Record = collections.namedtuple('Record', 'variant test size loops rawtime comment time bytes rate')
+
+def unique(rows, name):
+ """Takes a list of values, pulls out the named field, and returns
+ a list of the unique values of this field.
+ """
+ return sorted(set(getattr(x, name) for x in rows))
+
+def to_float(v):
+ """Convert a string into a better type.
+
+ >>> to_float('foo')
+ 'foo'
+ >>> to_float('1.23')
+ 1.23
+ >>> to_float('45')
+ 45
+ """
+ try:
+ if '.' in v:
+ return float(v)
+ else:
+ return int(v)
+ except:
+ return v
+
+def parse():
+ # Split the input up
+ rows = [x.strip().split(':') for x in fileinput.input()]
+ # Automatically turn numbers into the base type
+ rows = [[to_float(y) for y in x] for x in rows]
+
+ # Scan once to calculate the overhead
+ r = [Record(*(x + [0, 0, 0])) for x in rows]
+ bounces = pylab.array([(x.loops, x.rawtime) for x in r if x.test == 'bounce'])
+ fit = pylab.polyfit(bounces[:,0], bounces[:,1], 1)
+
+ records = []
+
+ for row in rows:
+ # Make a dummy record so we can use the names
+ r1 = Record(*(row + [0, 0, 0]))
+
+ bytes = r1.size * r1.loops
+ # Calculate the bounce time
+ delta = pylab.polyval(fit, [r1.loops])
+ time = r1.rawtime - delta
+ rate = bytes / time
+
+ records.append(Record(*(row + [time, bytes, rate])))
+
+ return records
+
+def plot(records, field, scale, ylabel):
+ variants = unique(records, 'variant')
+ tests = unique(records, 'test')
+
+ # A little hack. We want the 'all' record to be drawn last so
+ # that it's obvious on the graph. Assume that no tests come
+ # before it alphabetically
+ variants.reverse()
+
+ for test in tests:
+ for variant in variants:
+ v = [x for x in records if x.test==test and x.variant==variant]
+ v.sort(key=lambda x: x.size)
+ V = pylab.array([(x.size, getattr(x, field)) for x in v])
+
+ try:
+ # A little hack. We want the 'all' to be obvious on
+ # the graph
+ if variant == 'all':
+ pylab.scatter(V[:,0], V[:,1]/scale, label=variant)
+ pylab.plot(V[:,0], V[:,1]/scale)
+ else:
+ pylab.plot(V[:,0], V[:,1]/scale, label=variant)
+
+ except Exception, ex:
+ # michaelh1 likes to run this script while the test is
+ # still running which can lead to bad data
+ print ex
+
+ pylab.legend(loc='lower right')
+ pylab.semilogx()
+ pylab.xlabel('Block size (B)')
+ pylab.ylabel(ylabel)
+ pylab.title('%s %s' % (test, field))
+ pylab.grid()
+
+ pylab.savefig('%s-%s.png' % (test, field), dpi=100)
+ pylab.semilogx()
+ pylab.savefig('%s-%s-semilog.png' % (test, field), dpi=100)
+ pylab.clf()
+
+def test():
+ import doctest
+ doctest.testmod()
+
+def main():
+ records = parse()
+
+ plot(records, 'rate', 1024**2, 'Rate (MB/s)')
+ plot(records, 'time', 1, 'Total time (s)')
+
+if __name__ == '__main__':
+ main()