Created
February 25, 2014 10:39
-
-
Save gosub/9206636 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import sys | |
ms = int(sys.argv[1]) if len(sys.argv) > 1 else 250 | |
words, start = 0, time.time() | |
print "\n"*2 | |
try: | |
for line in sys.stdin: | |
for word in line.split(): | |
sys.stdout.write("\r %-30s" % (word,)) | |
sys.stdout.flush() | |
if any(punct in word for punct in ',.!?;:'): | |
time.sleep(0.001 * ms * 2) | |
else: | |
time.sleep(0.001 * ms) | |
words += 1 | |
except KeyboardInterrupt: | |
pass | |
finally: | |
secs = int(time.time() - start) | |
print ("%d words in %d seconds" % (words, secs)) | |
if secs: | |
print ("%d words/second, %d words/minute" % (words/secs, words*60/secs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment