| 1 |
from __future__ import print_function |
| 2 |
|
| 3 |
def jit_simple_loop(): |
| 4 |
print("simple loop") |
| 5 |
|
| 6 |
i = 0 |
| 7 |
while i < 200: |
| 8 |
i = i + 3 |
| 9 |
print(i) |
| 10 |
|
| 11 |
|
| 12 |
def jit_simple_inplace_add(): |
| 13 |
print("simple loop with inplace_add") |
| 14 |
|
| 15 |
i = 0 |
| 16 |
while i < 200: |
| 17 |
i += 3 |
| 18 |
print(i) |
| 19 |
|
| 20 |
def jit_range(): |
| 21 |
print("range object, but outside the loop") |
| 22 |
|
| 23 |
s = 0 |
| 24 |
for i in range(200): |
| 25 |
s = s + i |
| 26 |
print(s) |
| 27 |
|
| 28 |
def jit_exceptions(): |
| 29 |
try: |
| 30 |
i = 200 |
| 31 |
while i > 0: |
| 32 |
if i == 10: |
| 33 |
raise IndexError |
| 34 |
i -= 1 |
| 35 |
except IndexError: |
| 36 |
pass |
| 37 |
else: |
| 38 |
raise AssertionError |
| 39 |
|
| 40 |
def jit_simple_bridge(): |
| 41 |
s = 0 |
| 42 |
for i in range(200): |
| 43 |
if i % 2: |
| 44 |
s += 1 |
| 45 |
else: |
| 46 |
s += 2 |
| 47 |
print(s) |
| 48 |
|
| 49 |
def jit_tuple_indexing(): |
| 50 |
t = (1, 2, 3) |
| 51 |
i = 0 |
| 52 |
while i < 200: |
| 53 |
t = t[1], t[2], t[0] |
| 54 |
i += 1 |
| 55 |
print(t) |
| 56 |
|
| 57 |
def jit_nested_loop(): |
| 58 |
print("Arbitrary test function.") |
| 59 |
n = 100 |
| 60 |
i = 0 |
| 61 |
x = 1 |
| 62 |
while i<n: |
| 63 |
j = 0 |
| 64 |
while j<=i: |
| 65 |
j = j + 1 |
| 66 |
x = x + (i&j) |
| 67 |
i = i + 1 |
| 68 |
print(x) |
| 69 |
return x |
| 70 |
|
| 71 |
def jit_another_loop(): |
| 72 |
n = "hello" |
| 73 |
i = 0 |
| 74 |
while i < 150: |
| 75 |
i = i + 1 |
| 76 |
print(n) |
| 77 |
|
| 78 |
def jit_loop_with_call(): |
| 79 |
i = 0 |
| 80 |
k = 0 |
| 81 |
while i < 20000: |
| 82 |
k += call(i) |
| 83 |
i += 1 |
| 84 |
|
| 85 |
def call(i): |
| 86 |
k = 0 |
| 87 |
for j in range(i, i + 2): |
| 88 |
if j > i + 2: |
| 89 |
raise Exception("Explode") |
| 90 |
k += 1 |
| 91 |
return k |
| 92 |
|
| 93 |
def jit_importing_posixpath(): |
| 94 |
import os |
| 95 |
import posixpath |
| 96 |
|
| 97 |
def jit_importing_site(): |
| 98 |
import site |
| 99 |
|
| 100 |
def jit_unicode_formatting(): |
| 101 |
d = [] |
| 102 |
for i in range(1000): |
| 103 |
d[i] = u'\\xyz%d' % i |