| 1 |
""" |
| 2 |
Input for test_profile.py and test_cprofile.py. |
| 3 |
|
| 4 |
IMPORTANT: This stuff is touchy. If you modify anything above the |
| 5 |
test class you'll have to regenerate the stats by running the two |
| 6 |
test files. |
| 7 |
|
| 8 |
*ALL* NUMBERS in the expected output are relevant. If you change |
| 9 |
the formatting of pstats, please don't just regenerate the expected |
| 10 |
output without checking very carefully that not a single number has |
| 11 |
changed. |
| 12 |
""" |
| 13 |
|
| 14 |
import sys |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
TICKS = 42000 |
| 21 |
|
| 22 |
def timer(): |
| 23 |
return TICKS |
| 24 |
|
| 25 |
def testfunc(): |
| 26 |
|
| 27 |
|
| 28 |
global TICKS |
| 29 |
TICKS += 99 |
| 30 |
helper() |
| 31 |
helper() |
| 32 |
TICKS += 171 |
| 33 |
factorial(14) |
| 34 |
|
| 35 |
def factorial(n): |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
global TICKS |
| 41 |
if n > 0: |
| 42 |
TICKS += n |
| 43 |
return mul(n, factorial(n-1)) |
| 44 |
else: |
| 45 |
TICKS += 11 |
| 46 |
return 1 |
| 47 |
|
| 48 |
def mul(a, b): |
| 49 |
|
| 50 |
|
| 51 |
global TICKS |
| 52 |
TICKS += 1 |
| 53 |
return a * b |
| 54 |
|
| 55 |
def helper(): |
| 56 |
|
| 57 |
|
| 58 |
global TICKS |
| 59 |
TICKS += 1 |
| 60 |
helper1() |
| 61 |
TICKS += 2 |
| 62 |
helper1() |
| 63 |
TICKS += 6 |
| 64 |
helper2() |
| 65 |
TICKS += 3 |
| 66 |
helper2() |
| 67 |
TICKS += 2 |
| 68 |
helper2() |
| 69 |
TICKS += 5 |
| 70 |
helper2_indirect() |
| 71 |
TICKS += 1 |
| 72 |
|
| 73 |
def helper1(): |
| 74 |
|
| 75 |
|
| 76 |
global TICKS |
| 77 |
TICKS += 10 |
| 78 |
hasattr(C(), "foo") |
| 79 |
TICKS += 19 |
| 80 |
lst = [] |
| 81 |
lst.append(42) |
| 82 |
sys.exc_info() |
| 83 |
|
| 84 |
def helper2_indirect(): |
| 85 |
helper2() |
| 86 |
factorial(3) |
| 87 |
|
| 88 |
def helper2(): |
| 89 |
|
| 90 |
|
| 91 |
global TICKS |
| 92 |
TICKS += 11 |
| 93 |
hasattr(C(), "bar") |
| 94 |
TICKS += 13 |
| 95 |
subhelper() |
| 96 |
TICKS += 15 |
| 97 |
|
| 98 |
def subhelper(): |
| 99 |
|
| 100 |
|
| 101 |
global TICKS |
| 102 |
TICKS += 2 |
| 103 |
for i in range(2): |
| 104 |
try: |
| 105 |
C().foo |
| 106 |
except AttributeError: |
| 107 |
TICKS += 3 |
| 108 |
|
| 109 |
class C: |
| 110 |
def __getattr__(self, name): |
| 111 |
|
| 112 |
|
| 113 |
global TICKS |
| 114 |
TICKS += 1 |
| 115 |
raise AttributeError |