{ "info": { "author": "Alex King", "author_email": "alex_w_king@yahoo.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# Memoize with Timeout\n\nFunction decorator and anciliary tooling to \"memoize\", or cache return values from a function call. Timeouts are important to ensure that the cache doesn't grow indefinitely, and has the advantage of culling on length since it is less subject to thrashing.\n\n## Getting Started\n\n### Installing\n\nMWT can be installed using pip:\n\n $ pip install mwt\n\nIf you want to run the latest version of the code, you can install from git:\n\n $ pip install -U git+git://github.com/...\n\n### Using MWT\n\nAt its simplest, simply decorate your method with MWT:\n\n import timeit\n from mwt import mwt\n\n @mwt()\n def fibonacci(n):\n a,b = 1,1\n\n for i in range(n-1):\n a,b = b,a+b\n\n return a\n\n def test():\n fibonacci(5)\n\n for i in range(5):\n print timeit.timeit(\"fibonacci(50000)\", \"from __main__ import fibonacci\", number=1)\n\n pi@pi:/tmp $ python fib.py\n 0.470113992691\n 4.10079956055e-05\n 3.50475311279e-05\n 3.88622283936e-05\n 2.59876251221e-05\n\n\n### A Note of Caution\n\nJust because you can do something, it doesn't mean that you should.\n\nThe MWT decorator is a quick and easy way to resduce extended time in\ncalculation, but it is by definition not perfect: there are overheads to\nthe memoization and garbage collection process implicit in memoization,\nand caution in its use is presented.\n\nIn particular, watch out for the overall time executed, and secondly\nthe cache hit ratio: if the percentage of hits is small, then the net\neffect is to add overhead, not reduce it.\n\nThere are two things that can be done to evaluate performance. The first\nand most obvious is to profile timings and see whether time overall has\nbeen saved with the addition of the decorator.\n\nThe other is to analyze cache statistics after the containing code has been\nrunning for a while. MWT provides a stats interface to assist with this,\nand it can be utilized like this:\n\n fmt = \"%-15s %8s %8s %8s %8s %8s %8s\"\n print(fmt%(\"Cache\", \"Length\", \"Hits\", \"Misses\", \"Purged\",\n \"Timeouts\", \"HWM\"))\n stats = mwt.stats()\n for stat in stats:\n print(fmt%(stat[\"cache\"], stat[\"length\"], stat[\"hits\"],\n stat[\"misses\"], stat[\"purged\"], stat[\"timeouts\"],\n stat[\"hwm\"]))\n\nWhich will produce output like this which will allow you to see how\neffective the memoization process is for each of the functions that are\ndecorated:\n\n Cache Length Hits Misses Purged Timeouts HWM\n opc.hue:rgbToHsv 0 0 0 0 0 0\n opc.hue:hue 0 0 0 0 0 0\n opc.hue:hsvToRgb 27167 32785 270 5103 0 27183\n\nA high hit:miss ratio indicates that the cache is performing well.\n\nIf the ratio is poor, though, then don't give up straight away: it's\npossible that matters may be improved by tweaking the target method's\ncalling parameters (for example, bounding a float to perhaps a couple of\ndigits of precision).\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us.\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/your/project/tags). \n\n## Authors\n\n* **Alex King** - *Initial work* - [ak15199](https://github.com/ak15199)\n\nSee also the list of [contributors](https://github.com/your/project/contributors) who participated in this project.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n\n## Acknowledgments\n\nBased on inspiration from [MEMOIZE DECORATOR WITH TIMEOUT (PYTHON RECIPE)](http://code.activestate.com/recipes/325905-memoize-decorator-with-timeout/)\n\n\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ak15199/mwt.git", "keywords": "memoize cache python function decorator", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "mwt", "package_url": "https://pypi.org/project/mwt/", "platform": "", "project_url": "https://pypi.org/project/mwt/", "project_urls": { "Homepage": "https://github.com/ak15199/mwt.git" }, "release_url": "https://pypi.org/project/mwt/0.9.2/", "requires_dist": null, "requires_python": "", "summary": "Memoize with timeout", "version": "0.9.2" }, "last_serial": 3555962, "releases": { "0.9.0": [ { "comment_text": "", "digests": { "md5": "779dbfd50e8726caedfb601e1bfa5138", "sha256": "cb5bd13fe0fba34915d46317284c72c949cf267add9c6f00d6a5b6371a7e9743" }, "downloads": -1, "filename": "mwt-0.9.0.tar.gz", "has_sig": false, "md5_digest": "779dbfd50e8726caedfb601e1bfa5138", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3655, "upload_time": "2018-02-04T02:28:43", "url": "https://files.pythonhosted.org/packages/4f/ca/bc60e3c44682bd356784e9d72b12096d11e426a006857bab7ea05eb905c6/mwt-0.9.0.tar.gz" } ], "0.9.0b1": [ { "comment_text": "", "digests": { "md5": "a121929d89f718cf7495f7087f3ae3f5", "sha256": "cf32bfadf7a5e4c8616736727f23c656b820b0fbb757db0b0770140bb5dce5d5" }, "downloads": -1, "filename": "mwt-0.9.0b1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "a121929d89f718cf7495f7087f3ae3f5", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 5542, "upload_time": "2018-02-04T02:28:40", "url": "https://files.pythonhosted.org/packages/f8/38/143cf16bb4f89f19aab2b5305ee26a7b6258ed0f1393537ba40e1911a0c5/mwt-0.9.0b1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2afdf28eb89576a3a7c262ce1426d2fa", "sha256": "6ed1ad873a14523b0d12177e4dd2f141e44a5344a453fafa29ec3b9a59271d18" }, "downloads": -1, "filename": "mwt-0.9.0b1.tar.gz", "has_sig": false, "md5_digest": "2afdf28eb89576a3a7c262ce1426d2fa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3666, "upload_time": "2018-02-04T02:28:41", "url": "https://files.pythonhosted.org/packages/90/61/f090ac689653714b0da294a4cb63553d8109119feafe7ea3e43e14558067/mwt-0.9.0b1.tar.gz" } ], "0.9.1": [ { "comment_text": "", "digests": { "md5": "609406259c701a24e7b2932a27095df4", "sha256": "0012e7d0d868b1348582e770e08063d0a4a0f3a28c3f1fc0312f4503935fd6ba" }, "downloads": -1, "filename": "mwt-0.9.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "609406259c701a24e7b2932a27095df4", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7658, "upload_time": "2018-02-06T04:21:06", "url": "https://files.pythonhosted.org/packages/e5/de/0c311ac37cd3368c2a403d5db2bf4162844823c59ad3a4d52d231b4ecd4c/mwt-0.9.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "981307f52c314e1ded6607628af98bf5", "sha256": "d3b78254cbf0e89f0730c5ec611f1011b969c6f83852027a528ef22fd908feb1" }, "downloads": -1, "filename": "mwt-0.9.1.tar.gz", "has_sig": false, "md5_digest": "981307f52c314e1ded6607628af98bf5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4934, "upload_time": "2018-02-06T04:21:07", "url": "https://files.pythonhosted.org/packages/f0/ef/aeda55aa4c5aa5a4b447306a99bb8c7d59902b7e390c5372fe496d4ecb25/mwt-0.9.1.tar.gz" } ], "0.9.2": [ { "comment_text": "", "digests": { "md5": "39ea5b3841354a011f5cbef9cc07e1c5", "sha256": "66b318166b9005c6c44d62de71a81913f9a9f68f7c09ca155438772c7a42b1a7" }, "downloads": -1, "filename": "mwt-0.9.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "39ea5b3841354a011f5cbef9cc07e1c5", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7730, "upload_time": "2018-02-06T05:47:56", "url": "https://files.pythonhosted.org/packages/a8/aa/a4db2c04e37a1daf968e959d42fbefb21c56682bbdf892faef35506a1923/mwt-0.9.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3990d015c2d34fade3eb603d0de12498", "sha256": "80be6be2a989f3ae5f0870fdfaee1c52b0603cceed051ae9b788e0de5d952240" }, "downloads": -1, "filename": "mwt-0.9.2.tar.gz", "has_sig": false, "md5_digest": "3990d015c2d34fade3eb603d0de12498", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5006, "upload_time": "2018-02-06T05:47:58", "url": "https://files.pythonhosted.org/packages/7b/a6/9897f171724d10e18837b931dab75af673fab03c97a72711086aebc139bf/mwt-0.9.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "39ea5b3841354a011f5cbef9cc07e1c5", "sha256": "66b318166b9005c6c44d62de71a81913f9a9f68f7c09ca155438772c7a42b1a7" }, "downloads": -1, "filename": "mwt-0.9.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "39ea5b3841354a011f5cbef9cc07e1c5", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7730, "upload_time": "2018-02-06T05:47:56", "url": "https://files.pythonhosted.org/packages/a8/aa/a4db2c04e37a1daf968e959d42fbefb21c56682bbdf892faef35506a1923/mwt-0.9.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3990d015c2d34fade3eb603d0de12498", "sha256": "80be6be2a989f3ae5f0870fdfaee1c52b0603cceed051ae9b788e0de5d952240" }, "downloads": -1, "filename": "mwt-0.9.2.tar.gz", "has_sig": false, "md5_digest": "3990d015c2d34fade3eb603d0de12498", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5006, "upload_time": "2018-02-06T05:47:58", "url": "https://files.pythonhosted.org/packages/7b/a6/9897f171724d10e18837b931dab75af673fab03c97a72711086aebc139bf/mwt-0.9.2.tar.gz" } ] }