Skip to content

Commit fe62512

Browse files
committed
week 09 updates
1 parent e18b22d commit fe62512

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+5063
-11
lines changed
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import random
2+
import sys
3+
import threading
4+
import time
5+
6+
lock = threading.Lock()
7+
8+
def write():
9+
lock.acquire()
10+
sys.stdout.write( "%s writing.." % threading.current_thread().name)
11+
time.sleep(random.random())
12+
sys.stdout.write( "..done\n")
13+
lock.release()
14+
15+
16+
while True:
17+
thread = threading.Thread(target=write)
18+
thread.start()
19+
time.sleep(.1)
20+
Binary file not shown.
242 KB

Examples/week-07-profiling/pygame/swarm.py renamed to Examples/week-09-profiling/pygame/swarm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# from meliae import scanner
77
# scanner.dump_all_objects("meliae.dump") # you can pass a file-handle if you prefer
88

9-
NUMBER_OF_SPHERES = 150
9+
NUMBER_OF_SPHERES = 2
1010

1111
size = width, height = 800, 600
1212
pygame.init()
@@ -18,8 +18,8 @@ def __init__(self):
1818
self.ball = pygame.image.load("ball.gif")
1919
self.x = random.random() * width
2020
self.y = random.random() * height
21-
vx = 150*(random.random() - .5)
22-
vy = 150*(random.random() - .5)
21+
vx = 250*(random.random() - .5)
22+
vy = 250*(random.random() - .5)
2323
self.v = [vx, vy]
2424

2525
def update_v(self, other ):

Examples/week-07-profiling/strings/str_comprehensions.py renamed to Examples/week-09-profiling/strings/str_comprehensions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from timer import timer
12

2-
@profile
3+
# @profile
4+
@timer
35
def slow():
46
s = ""
57
with open('/usr/share/dict/words') as f:
@@ -9,7 +11,8 @@ def slow():
911

1012
return words
1113

12-
@profile
14+
# @profile
15+
@timer
1316
def fast():
1417
with open('/usr/share/dict/words') as f:
1518
words = [w.upper() for w in f ]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
�c_line_profiler
2+
LineStats
3+
q)�q}q(UunitqG>������Utimingsq}ub.

0 commit comments

Comments
 (0)