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)
print
31 comments:
Jocylenn Grace Behrens was born at home on 5/16/2009 at 11:47PM after 6.5 hours of labor. She weighed 10lbs 8oz. Both her and my wife are recovering nicely, and we're all grateful for their good health.
Wow, congratulations to both of you.
Congratulations !
>>> 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))
Congrats! :)
Congratulations!
P.S. That's one of the geekiest baby announcements I've ever read :-)
Congratulations Friend, I'm very happy for both of you. I have been following the updates on Facebook. I miss you both and can't wait to see you all again. Take care. Your buddy and long time friend, Joe Murphy
Congratulations and best wishes to you and yours.
Gratz!!!11!1!!!
JJ,
Congratulations to you and the lady of the house.
That's great news.
Carl T.
Tarek:
[84, 104, 97, 110, 107, 115, 44, 32, 84, 97, 114, 101, 107, 33]
Thanks, everyone!
Congratulations JJ!
-Simeon
Many congratulations. Glad mother and daughter are both doing well.
Congratulations! How many children is that now?
Congrats, JJ.
May God richly bless you and your family for your generosity to the service of life!
congratulations!
The midwife corrected me. It turns out that she didn't grab the baby by the head. She slipped in her hand and hooked a finger under the baby's armpit. I was wondering how she could yank so hard without hurting the baby's neck ;) I guess those are the tricks you learn after you've delivered a few thousand kids!
Hearty wishes and Congratulations!!!
> Congratulations! How many children is that now?
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!
> 5!
120 kids? Wow :-)
Congratulations to both of you.
> 120 kids? Wow :-)
Yeah, but to be fair, some of those were multiples ;)
/me giggles
Congrats to you both! Knowing you, I suppose plans for the next release, JJ 6.0, are already in the works. :P
Congrats dude! Heather and I are very happy for you guys. And holy crap, that's a big kid. A Behrens for sure. Can't wait to meet her.
'eJxzzs9LL0osKVYoyVeozC9VSMxLUSjJSFXIzQeSRYoK4ZnFGZl56XA5IF2kkJaYm5lTqZCVXwkW\ny0gsKMjMSy0uVlSwcgEAuH0dDw==\n'.decode("base64").decode("zlib")
Thanks Bob and Kelly!
Alex--cute ;)
Congrates! Will she drink the AntiGravity Cola? :)
JJ, congratulations from Ukraine! Wish you God's Bless and good health for baby, mother and whole family.
Thanks, Ivan :)
I wanted to thank you for the program you posted. I have added to it a little for my use and wanted to show you what I have done with it... This is being run from ipython console with the -pylab option.
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")
Hahahaha!!! Congrats!!! Did you do this while she was in labor?
Post a Comment