stoichiograph

Spell words with elemental symbols from the periodic table.
Log | Files | Refs | LICENSE

commit 5be69c40ecc6cbc2a97235678e1b454a827d2ae7
parent b8343e0b2cced71422204fc2a160124565a2bd36
Author: Amin Mesbah <mesbah.amin@gmail.com>
Date:   Thu, 19 Jan 2017 00:25:13 -0800

Use memoization in generate_groupings().

This improves performance significantly when processing long lists of
words.

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():