/tmp/tachyon_selfcontained.py - Heatmap

1,054
Self Samples
4,236
Cumulative
24
Lines Hit
100.00%
% of Total
206
Max Self
1054
Max Total
Intensity:
Cold → Hot
Self Time
Total Time
Show All
Hot Only
Heat
Specialization
Line
Self
Total
Code
1
"""
2
Tachyon Demo - Self-contained profiling example.
3
Pure Python with no external imports for clean heatmap output.
4
"""
5
6
7
1
1
def fibonacci(n):
8
"""Recursive fibonacci - creates deep call stacks."""
9
3
3
if n <= 1:
10
17
17
return n
11
206
227
return fibonacci(n - 1) + fibonacci(n - 2)
12
13
14
def bubble_sort(arr):
15
"""Classic bubble sort - O(n^2) comparison sorting."""
16
n = len(arr)
17
for i in range(n):
18
2
2
for j in range(0, n - i - 1):
19
8
8
if arr[j] > arr[j + 1]:
20
2
2
arr[j], arr[j + 1] = arr[j + 1], arr[j]
21
return arr
22
23
24
def matrix_multiply(a, b):
25
"""Matrix multiplication using nested loops."""
26
rows_a, cols_a = len(a), len(a[0])
27
rows_b, cols_b = len(b), len(b[0])
28
result = [[0] * cols_b for _ in range(rows_a)]
29
30
for i in range(rows_a):
31
for j in range(cols_b):
32
8
8
for k in range(cols_a):
33
62
62
result[i][j] += a[i][k] * b[k][j]
34
return result
35
36
37
def prime_sieve(limit):
38
"""Sieve of Eratosthenes - find all primes up to limit."""
39
is_prime = [True] * (limit + 1)
40
is_prime[0] = is_prime[1] = False
41
42
for num in range(2, int(limit ** 0.5) + 1):
43
if is_prime[num]:
44
1
1
for multiple in range(num * num, limit + 1, num):
45
is_prime[multiple] = False
46
47
2
2
return [num for num, prime in enumerate(is_prime) if prime]
48
49
50
def string_processing(iterations):
51
"""String operations - concatenation and formatting."""
52
for _ in range(iterations):
53
result = ""
54
for i in range(50):
55
91
91
result += f"item_{i}_"
56
22
22
parts = result.split("_")
57
10
10
joined = "-".join(parts)
58
59
60
def list_operations(iterations):
61
"""List comprehensions and operations."""
62
for _ in range(iterations):
63
118
118
squares = [x ** 2 for x in range(500)]
64
119
119
evens = [x for x in squares if x % 2 == 0]
65
12
12
total = sum(evens)
66
67
68
def dict_operations(iterations):
69
"""Dictionary creation and lookups."""
70
for _ in range(iterations):
71
206
206
data = {f"key_{i}": i ** 2 for i in range(200)}
72
158
158
values = [data[f"key_{i}"] for i in range(200)]
73
5
5
total = sum(values)
74
75
76
def compute_heavy():
77
"""CPU-intensive computation section."""
78
1
301
fibonacci(30)
79
80
size = 60
81
a = [[i + j for j in range(size)] for i in range(size)]
82
b = [[i * j for j in range(size)] for i in range(size)]
83
matrix_multiply(a, b)
84
85
prime_sieve(10000)
86
87
88
def data_processing():
89
"""Data structure operations."""
90
753
string_processing(2000)
91
list_operations(1500)
92
dict_operations(1000)
93
94
data = list(range(800))
95
for _ in range(3):
96
data = data[::-1]
97
bubble_sort(data[:200])
98
99
100
def main():
101
"""Main entry point."""
102
1,054
compute_heavy()
103
data_processing()
104
105
106
if __name__ == "__main__":
107
1,054
main()