Browse Source

added test func

multiprocess_search
Raphael Roberts 7 years ago
parent
commit
043ea7a56a
  1. 8
      hangman.py
  2. 7
      test_mp.py

8
hangman.py

@ -1,11 +1,11 @@
from string import ascii_lowercase as alphabet
import codecs import codecs
import hashlib import hashlib
import json import json
import os
import multiprocessing import multiprocessing
import os
import pickle import pickle
import re import re
from string import ascii_lowercase as alphabet
import sys import sys
#32 or 64 bit platform? #32 or 64 bit platform?
if sys.maxsize > 2**32: if sys.maxsize > 2**32:
@ -78,10 +78,10 @@ class bool_regex:
return bool(self.expr.match(arg)) return bool(self.expr.match(arg))
def filter_wordlist(input,remaining_letters,word_list,mp=True): def filter_wordlist(input,remaining_letters,word_list,mp=True):
regex = re.compile(input.replace('.','[{}]'.format(''.join(remaining_letters))) + '$') regex = re.compile(input.replace('.','[{}]'.format(''.join(remaining_letters))) + '$')
if mp:
if mp and len(word_list) > 1000:
regex = bool_regex(regex) regex = bool_regex(regex)
pool = multiprocessing.Pool() pool = multiprocessing.Pool()
matches = pool.map(regex,word_list)
matches = pool.map(regex,word_list,100_000)
pool.close() pool.close()
pool.join() pool.join()
else: else:

7
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)
Loading…
Cancel
Save