pry includes functionality to allow quick-and-dirty profiling and benchmarking of code. Consider the following simple example test module:
import libpry
def fib1(n):
lst, a, b = [], 0, 1
while len(lst) < n:
lst.append(b)
a, b = b, a+b
return lst
class ProfTest(libpry.AutoTree):
def test_one(self):
assert fib1(10) == [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
tests = [
ProfTest()
]
The -n flag specifies the number of times each test being run should be repeated. When the verbosity is bumped up to show individual test timings (-vv), this is a handy quick comparative benchmarking tool.
> pry -vvn 100000 test_profile.py ./test_profile.ProfTest.test_one . OK (0.585s) 1 tests (pass: 1) - 0.585s
The -p flag specifies that a profile run should be done:
> pry -pn 10000 test_profile.py . 1 tests (pass: 1) - 0.234s PROFILE ======= ./test_profile.ProfTest.test_one 250000 function calls in 0.209 CPU seconds Ordered by: internal time ncalls tottime percall cumtime percall filename:lineno(function) 10000 0.117 0.000 0.180 0.000 ./test_profile.py:3(fib1) 100000 0.032 0.000 0.032 0.000 {method 'append' of 'list' objects} 110000 0.031 0.000 0.031 0.000 {len} 10000 0.015 0.000 0.195 0.000 ./test_profile.py:11(test_one)
Copyright Nullcube 2008