Skip to content

Commit

Permalink
Episode: Line Level Profiling (#7)
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
Robadob committed Jan 29, 2024
1 parent 62d2f9c commit b069e6c
Show file tree
Hide file tree
Showing 5 changed files with 538 additions and 4 deletions.
Binary file added episodes/fig/line_profiler-worked-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions episodes/files/bubblesort/bubblesort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys
import random

# Argument parsing
if len(sys.argv) != 2:
print("Script expects 1 positive integer argument, %u found."%(len(sys.argv) - 1))
sys.exit()
n = int(sys.argv[1])
# Init
random.seed(12)
arr = [random.random() for i in range(n)]
print("Sorting %d elements"%(n))
# Sort
for i in range(n - 1):
swapped = False
for j in range(0, n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
swapped = True
# If no two elements were swapped in the inner loop, the array is sorted
if not swapped:
break
# Validate
is_sorted = True
for i in range(n - 1):
if arr[i] > arr[i+1]:
is_sorted = False
print("Sorting: %s"%("Passed" if is_sorted else "Failed"))
23 changes: 23 additions & 0 deletions episodes/files/line_profiler-worked-example/fizzbuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
n = 100
a=0
b=0
c=0
d=0
for i in range(1, n + 1):
if i % 3 == 0 and i % 5 == 0:
a+=1
print("FizzBuzz")
elif i % 3 == 0:
b+=1
print("Fizz")
elif i % 5 == 0:
c+=1
print("Buzz")
else:
d+=1
print(i)

print(a)
print(b)
print(c)
print(d)
Loading

0 comments on commit b069e6c

Please sign in to comment.