I have this Python program that I haven't run in a couple years. I wanted to see if I could make it run faster. Last time, it took 22 hours. Sure enough, using some advanced optimization techniques (and a swig of castor oil), my wife and I were able to run the program in a mere 6.5 hours! Here it is:
#!/usr/bin/env python
"""Help Gina-Marie time her contractions."""
import time
SECS_PER_MIN = 60
last_start = None
while True:
print "Press enter when the contraction starts.",
raw_input()
start = time.time()
if last_start:
print "It's been %s minutes %s seconds since last contraction." \
% divmod(int(start - last_start), SECS_PER_MIN)
last_start = start
print "Press enter when the contraction stops.",
raw_input()
stop = time.time()
print "Contraction lasted %s seconds." % int(stop - start)

Comments
>>> def i_wish_you(something):
... print ''.join([chr(i) for i in something])
...
>>> i_wish_you((72, 97, 112, 112, 105, 110, 101, 115, 115))
P.S. That's one of the geekiest baby announcements I've ever read :-)
Congratulations to you and the lady of the house.
That's great news.
Carl T.
[84, 104, 97, 110, 107, 115, 44, 32, 84, 97, 114, 101, 107, 33]
-Simeon
May God richly bless you and your family for your generosity to the service of life!
5!
Tongue in cheek:
I figure now that I've got the process down, why should I stop? I'm going to tell everyone else to leave child rearing to the experts ;)
> May God richly bless you and your family for your generosity to the service of life!
Thanks, Eddy!
120 kids? Wow :-)
Congratulations to both of you.
Yeah, but to be fair, some of those were multiples ;)
/me giggles
Alex--cute ;)
import matplotlib.pyplot as plt
import time
spacing = [0]
dur = [0]
count = [0]
counter = 0
spacingholder = 0
SECS_PER_MIN = 60
last_start = None
while True:
print "Press enter when the contraction starts.",
raw_input()
start = time.time()
if last_start:
print "It's been %s minutes %s seconds since last contraction." \
% divmod(int(start - last_start), SECS_PER_MIN)
spacingholder = ((start - last_start)/60.0)
last_start = start
print "Press enter when the contraction stops.",
raw_input()
stop = time.time()
print "Contraction lasted %s seconds." % int(stop - start)
counter = counter + 1
dur.append(int(stop - start))
count.append(counter)
spacing.append(spacingholder)
plt.subplots_adjust(hspace=0.32,top=.93,bottom=.08) #tweak subplots so that labels fit
plt.figure(1)
plt.subplot(211)
plt.plot(count,spacing,"ro")
plt.xlabel("Contraction")
plt.ylabel("Minutes")
plt.title("Time Between Contractions")
plt.subplot(212)
plt.plot(count,dur,"ro")
plt.xlabel("Contraction")
plt.ylabel("Seconds")
plt.title("Duration of Contractions")