Pythonでプロファイラを使う - arosh/arosh.github.com GitHub Wiki

https://docs.python.jp/3/library/profile.html

from cProfile import Profile
p =  Profile()
p.enable()
# do something
p.disable()
# p.runcall を使っても良い
p.dump_stats('hoge.prof') # time.time() などを使っても良い
gprof2dot -f pstats --colour-nodes-by-selftime /tmp/profile/* > profile.dot && dot -Tpdf profile.dot -o profile.pdf

--show-samples はバイナリレベルで差がなかった。