From 043ea7a56af397e2571b754145054b8e5f9c8968 Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Sun, 11 Nov 2018 17:24:37 -0600 Subject: [PATCH] added test func --- hangman.py | 8 ++++---- test_mp.py | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 test_mp.py diff --git a/hangman.py b/hangman.py index 86fca70..ed8f1bd 100644 --- a/hangman.py +++ b/hangman.py @@ -1,11 +1,11 @@ +from string import ascii_lowercase as alphabet import codecs import hashlib import json -import os import multiprocessing +import os import pickle import re -from string import ascii_lowercase as alphabet import sys #32 or 64 bit platform? if sys.maxsize > 2**32: @@ -78,10 +78,10 @@ class bool_regex: return bool(self.expr.match(arg)) def filter_wordlist(input,remaining_letters,word_list,mp=True): regex = re.compile(input.replace('.','[{}]'.format(''.join(remaining_letters))) + '$') - if mp: + if mp and len(word_list) > 1000: regex = bool_regex(regex) pool = multiprocessing.Pool() - matches = pool.map(regex,word_list) + matches = pool.map(regex,word_list,100_000) pool.close() pool.join() else: diff --git a/test_mp.py b/test_mp.py new file mode 100644 index 0000000..888821a --- /dev/null +++ b/test_mp.py @@ -0,0 +1,7 @@ +import timeit +from hangman import load_words,filter_wordlist,ALPHABET +words = load_words('words.txt') +def test(): + times_mp = timeit.timeit("filter_wordlist('.....',ALPHABET,words,True)",number = 20,globals=globals()) + times_sc = timeit.timeit("filter_wordlist('.....',ALPHABET,words,False)",number = 20,globals=globals()) + return dict(time_mp=times_mp,times_sc=times_sc) \ No newline at end of file