Author: Maciej Fijalkowski <[email protected]> Branch: extradoc Changeset: r5441:e25d84db6be0 Date: 2014-10-18 15:47 +0200 http://bitbucket.org/pypy/extradoc/changeset/e25d84db6be0/
Log: (fijal, arigo) start working on slides diff --git a/talk/pyconpl-2014/benchmarks/abstract.rst b/talk/pyconpl-2014/benchmarks/abstract.rst new file mode 100644 --- /dev/null +++ b/talk/pyconpl-2014/benchmarks/abstract.rst @@ -0,0 +1,7 @@ +How to benchmark code +--------------------- + +In this talk, we would like to present basics of how the Python virtual machines +like CPython or PyPy work and how to use that knowledge to write meaningful +benchmarks for your programs. We'll show what's wrong with microbenchmarks +and how to improve the situation. diff --git a/talk/pyconpl-2014/benchmarks/f1.py b/talk/pyconpl-2014/benchmarks/f1.py new file mode 100644 --- /dev/null +++ b/talk/pyconpl-2014/benchmarks/f1.py @@ -0,0 +1,8 @@ + +def f(): + i = 0 + while i < 100000000: + i += 1 + return i + +f() diff --git a/talk/pyconpl-2014/benchmarks/f2.py b/talk/pyconpl-2014/benchmarks/f2.py new file mode 100644 --- /dev/null +++ b/talk/pyconpl-2014/benchmarks/f2.py @@ -0,0 +1,10 @@ + +def f(): + i = 0 + s = 0 + while i < 100000000: + s += len(str(i)) + i += 1 + return s + +print f() diff --git a/talk/pyconpl-2014/benchmarks/fib.py b/talk/pyconpl-2014/benchmarks/fib.py new file mode 100644 --- /dev/null +++ b/talk/pyconpl-2014/benchmarks/fib.py @@ -0,0 +1,27 @@ + +import time +import numpy +from matplotlib import pylab + +def fib(n): + if n == 0 or n == 1: + return 1 + return fib(n - 1) + fib(n - 2) + +def f(): + for i in range(10000): + "".join(list(str(i))) + +times = [] +for i in xrange(1000): + t0 = time.time() + #f() + fib(17) + times.append(time.time() - t0) + +hist, bins = numpy.histogram(times, 20) +#pylab.plot(bins[:-1], hist) +pylab.ylim(ymin=0, ymax=max(times) * 1.2) +pylab.plot(times) +#pylab.hist(hist, bins, histtype='bar') +pylab.show() diff --git a/talk/pyconpl-2014/benchmarks/talk.rst b/talk/pyconpl-2014/benchmarks/talk.rst new file mode 100644 --- /dev/null +++ b/talk/pyconpl-2014/benchmarks/talk.rst @@ -0,0 +1,78 @@ +--------------------- +How to benchmark code +--------------------- + +Who are we? +------------ + +xxx + +What is this talk is about? +--------------------------- + +* basics how CPython and PyPy run programs + +* a bit of theory about measuring performance + +* microbenchmarks + +* complicated picture of "real world" + +CPython +------- + +* a "simple" virtual machine + +* compiles python code to bytecode + +* runs the bytecode + +* usually invokes tons of runtime functions written in C + +CPython (demo) +-------------- + +PyPy +---- + +* not so simple virtual machine + +* all of the above + +* ... and then if the loop/function gets called often enough + it's compiled down to an optimized assembler by the JIT + +PyPy (demo) +----------- + +Measurments 101 +--------------- + +* run your benchmark multiple times + +* the distribution should be gaussian + +* take the average and the variation + +* if the variation is too large, increase the number of iterations + +Let's do it (demo) +------------------ + +Problems +-------- + +* the whole previous slide is a bunch of nonsense + +* ... + +"Solution" +---------- + +* you try your best and do the average anyway + +* presumably cutting off the warmup time + +|pause| + +* not ideal at all _______________________________________________ pypy-commit mailing list [email protected] https://mail.python.org/mailman/listinfo/pypy-commit
