stoichiograph

Spell words with elemental symbols from the periodic table.
git clone git://git.amin.space/stoichiograph.git
Log | Files | Refs | LICENSE

commit 3d73dfb5f62edf6fa50c3c63852628dca1a51a94
parent 25b007e43a45b13b655c582786d544ab25eb5529
Author: amin <dev@aminmesbah.com>
Date:   Thu, 19 Jan 2017 08:25:13 +0000

Use memoization in generate_groupings().

This improves performance significantly when processing long lists of
words.

FossilOrigin-Name: e8c75be723f489566dc520559c91cead7a1335789f9314f222ea0fcd5bcab4d7
Diffstat:
Mspeller.py | 3+++
Mstoichiograph.py | 2+-
2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/speller.py b/speller.py @@ -1,3 +1,4 @@ +from functools import lru_cache from itertools import chain, product import logging @@ -51,6 +52,7 @@ def spell(word, symbols=ELEMENTS): return elemental_spellings +@lru_cache(maxsize=None) def generate_groupings(word_length, batch_sizes=(1, 2)): """Return all groupings for a word of a given length. @@ -75,6 +77,7 @@ def generate_groupings(word_length, batch_sizes=(1, 2)): ) log.debug('Groupings: {}'.format(groupings)) + log.debug(generate_groupings.cache_info()) return groupings diff --git a/stoichiograph.py b/stoichiograph.py @@ -11,7 +11,7 @@ import speller __title__ = 'stoichiograph' __author__ = 'Amin Mesbah' __version__ = '0.0.1' -__description__='Spell words with elemental symbols from the periodic table.' +__description__ = 'Spell words with elemental symbols from the periodic table.' def get_args():