{ "info": { "author": "Quantum", "author_email": "quantum@dmoj.ca", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 1.10", "Framework :: Django :: 1.11", "Framework :: Django :: 1.8", "Framework :: Django :: 1.9", "Framework :: Django :: 2.0", "Framework :: Django :: 2.1", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# optimize-later [![Build Status](https://img.shields.io/travis/quantum5/optimize-later.svg)](https://travis-ci.org/quantum5/optimize-later) [![Coverage](https://img.shields.io/codecov/c/gh/quantum5/optimize-later.svg)](https://codecov.io/gh/quantum5/optimize-later) [![PyPI](https://img.shields.io/pypi/v/optimize-later.svg)](https://pypi.org/project/optimize-later/) [![PyPI - Format](https://img.shields.io/pypi/format/optimize-later.svg)](https://pypi.org/project/optimize-later/) [![PyPI - Django Version](https://img.shields.io/pypi/djversions/optimize-later.svg)](#django)\n\n> Premature optimization is the root of all evil (or at least most of it) in programming.\n>\n> -- Donald Knuth\n\nWouldn't it be nice to have something to tell you when optimization is really necessary?\n\nEnter `optimize-later`.\n\nInstead of trying to guess what code ought to be optimized, `optimize-later` times potentially\nslow blocks of code for you, and calls a user-specified function when it exceeds the specified\ntime limit. This way, you only have to optimize code when speed becomes a problem, saving you\nfrom both the evils of premature optimization, and the evils of slow code. \n\n## Usage\n\n```python\nfrom optimize_later import optimize_later, register_callback\n\n### Basic usage.\nwith optimize_later('test_block', 0.2):\n # potentially slow block of code...\n time.sleep(1)\n\n@register_callback\ndef my_report_function(report):\n # Short one line description.\n print(report.short())\n\n # Long description with breakdown based on blocks.\n print(report.long())\n\n # Details available in:\n # - report.name: block name\n # - report.limit: time limit\n # - report.delta: time consumed\n # - report.blocks: breakdown by blocks\n # - report.start, report.end: start and end time with an unspecified timer:\n # useful for building a relative timeline with blocks.\n\n### More advanced uses.\n# Automatic block names from file and source line (slightly slow).\nwith optimize_later(0.2):\n # potentially slow block of code...\n time.sleep(1)\n\n# Always warn. Good for exceptional cases that you suspect should not happen.\nwith optimize_later():\n # potentially slow block of code...\n time.sleep(1)\n\n# Also available as a decorator.\n@optimize_later('bad-function', 0.2)\ndef function_name():\n # potentially slow function...\n time.sleep(1)\n\n# Will use module:function as block name, if you do not specify a name.\n# There is no performance penalty this way, as the function name can be easily detected.\n@optimize_later(0.2)\ndef function_name():\n # potentially slow function...\n time.sleep(1)\n\n### Blocks.\nwith optimize_later() as o:\n with o.block('block 1'):\n # When the time limit of whole block is exceeded, your report will contain\n # a detailed breakdown by sub-blocks executed. This allows you to pinpoint\n # which exact block is the culprit.\n time.sleep(1)\n\n # optimize-later will automatically generate a block name for you from file and\n # line number, with a slightly performance penalty.\n with o.block() as b:\n # You can also nest blocks.\n with b.block():\n pass\n\n### Callbacks deregistration and contexts.\nfrom optimize_later import deregister_callback, optimize_context\n\nderegister_callback(my_report_function)\n\nwith optimize_context():\n # Register a callback here.\n register_callback(my_report_function)\n# Callback is not available here.\n\n@optimize_context\ndef function():\n # This callback will be available for the duration of this function.\n register_callback(my_report_function)\n\n# Remove global callbacks for this block.\nwith optimize_context(renew=True):\n pass\n# or...\n@optimize_context(renew=True)\ndef function():\n pass\n\n# Shortcut registration syntax.\nwith optimize_context(my_report_function):\n pass\n\n@optimize_context(my_report_function, renew=True)\ndef function():\n pass\n```\n\nA sample short report:\n\n```Block 'tests.py@152' took 0.011565s (+0.011565s over limit)```\n\nA sample long report:\n\n```\nBlock 'tests.py@152' took 0.011565s (+0.011565s over limit), children:\n - Block 'tests.py@153' took 0.006662s, children:\n - Block 'tests.py@154' took 0.000002s\n - Block 'tests.py@156' took 0.000002s\n - Block 'tests.py@159' took 0.000001s\n```\n\n## Installation\n\nInstall the module with:\n\n```\n$ pip install optimize-later\n```\n\nOr if you want the latest bleeding edge version:\n\n```\n$ pip install -e git://github.com/quantum5/optimize-later.git\n```\n\nThat's it!\n\n### Django\n\nIf you are using Django, you might want to configure `optimize-later` in `settings.py` instead of\nadding callbacks directly.\n\nYou have to add `'optimize_later'` to `INSTALLED_APPS`.\n\nThen, the list of callbacks as dot-separated import paths can be specified in `'OPTIMIZE_LATER_CALLBACKS'`\nin `settings.py`. For example:\n\n```python\nOPTIMIZE_LATER_CALLBACKS = [\n 'myapp.optimize.report',\n 'otherapp.optimize.report',\n]\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/quantum5/optimize-later", "keywords": "optimize profiler speed", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "optimize-later", "package_url": "https://pypi.org/project/optimize-later/", "platform": "", "project_url": "https://pypi.org/project/optimize-later/", "project_urls": { "Homepage": "https://github.com/quantum5/optimize-later" }, "release_url": "https://pypi.org/project/optimize-later/0.2/", "requires_dist": null, "requires_python": "", "summary": "Mark potentially slow blocks for notifications when it actually turns out too slow, so you can optimize it.", "version": "0.2" }, "last_serial": 4197268, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "ff30e306505e4db74e15b259bbae0c98", "sha256": "ccd290e529e55dd31a02fb981115e81296d87610023742f4de977e959d3512e1" }, "downloads": -1, "filename": "optimize_later-0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ff30e306505e4db74e15b259bbae0c98", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7570, "upload_time": "2017-08-14T00:40:32", "url": "https://files.pythonhosted.org/packages/58/ce/bb8e15af3c16be65c34c5b63af919c7206bee3640a6af84e945609d46c9c/optimize_later-0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "05280ee9dfce82d9b4a2c63d96721498", "sha256": "1073d15045eef97bf26928abf9334f0763b11a50d659e5c48c20aa499e8e0af2" }, "downloads": -1, "filename": "optimize-later-0.1.tar.gz", "has_sig": false, "md5_digest": "05280ee9dfce82d9b4a2c63d96721498", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4744, "upload_time": "2017-08-14T00:40:33", "url": "https://files.pythonhosted.org/packages/40/a7/aca99fbfd8c4ca3836bc85934dd351bc83247790dd793517a2aa03d6d5fa/optimize-later-0.1.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "ab694888c48d26e415dc755a51b36d01", "sha256": "f94a62ff2261b799c45e90736787617c41ab2c1405948c618e2833f8fd672ded" }, "downloads": -1, "filename": "optimize_later-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "ab694888c48d26e415dc755a51b36d01", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8439, "upload_time": "2017-08-14T22:33:32", "url": "https://files.pythonhosted.org/packages/8a/ee/464dcf5cee86f642ec1b71e87fb0857481073f0020ead1280962323dbc9d/optimize_later-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "642a791abe54e55bbfa796a846a2a15a", "sha256": "632416b9d96f1c434de8b80bba0c26f0aea0d46740c77d51dbed0c58dc7aa26e" }, "downloads": -1, "filename": "optimize-later-0.1.1.tar.gz", "has_sig": false, "md5_digest": "642a791abe54e55bbfa796a846a2a15a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5043, "upload_time": "2017-08-14T22:33:34", "url": "https://files.pythonhosted.org/packages/6f/53/abe2586c486cdee3af8263e360c965e3e246830f37d75d0c47d5094ae840/optimize-later-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "804cb7fe5266933bbc87d9175b8667dd", "sha256": "3bd5cec6fd3aceb70fd0e49a557abb835b794e594c55e2b9bd1ace2cfe1c1d0a" }, "downloads": -1, "filename": "optimize_later-0.1.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "804cb7fe5266933bbc87d9175b8667dd", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9191, "upload_time": "2018-08-22T18:25:21", "url": "https://files.pythonhosted.org/packages/6c/0c/fc936b58d15ed07a5b6d6e815389facc84f2fa44aab379f95dac44e98f6f/optimize_later-0.1.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "444ee4704825e84eaf2d61c4188cc7e8", "sha256": "7cd98ae7c29640f43577a8c4b7105ca497676d0ff4d7012892d27fd2646ffb69" }, "downloads": -1, "filename": "optimize-later-0.1.2.tar.gz", "has_sig": false, "md5_digest": "444ee4704825e84eaf2d61c4188cc7e8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8048, "upload_time": "2018-08-22T18:25:23", "url": "https://files.pythonhosted.org/packages/db/e6/5e9d068b67ebc78088a72b78af1a6eae70cab14e97f8f6e86bd26f82e57e/optimize-later-0.1.2.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "db230fe5e34f4996621014664f863c93", "sha256": "6a0c4d55ec945f84fa1e61ccdc598bfce206e4fb2f869484953b041aa62f1b02" }, "downloads": -1, "filename": "optimize_later-0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "db230fe5e34f4996621014664f863c93", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9219, "upload_time": "2018-08-22T18:44:11", "url": "https://files.pythonhosted.org/packages/13/5a/2c6107f9f88b6d7a60f5f14d69f980bef2a3f09dbc9263b1c5be89f60a15/optimize_later-0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "da862b3be5698a2535131a0e44f83cbf", "sha256": "6b81c6b5156c59f4e70fd5a7a9aef788f2bb7832482f7c4a25ff2c3812ba2ba4" }, "downloads": -1, "filename": "optimize-later-0.2.tar.gz", "has_sig": false, "md5_digest": "da862b3be5698a2535131a0e44f83cbf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8127, "upload_time": "2018-08-22T18:44:12", "url": "https://files.pythonhosted.org/packages/56/93/563571529cb7120cb2980d86551f403ce386cc3b756395263ed31f4755ae/optimize-later-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "db230fe5e34f4996621014664f863c93", "sha256": "6a0c4d55ec945f84fa1e61ccdc598bfce206e4fb2f869484953b041aa62f1b02" }, "downloads": -1, "filename": "optimize_later-0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "db230fe5e34f4996621014664f863c93", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9219, "upload_time": "2018-08-22T18:44:11", "url": "https://files.pythonhosted.org/packages/13/5a/2c6107f9f88b6d7a60f5f14d69f980bef2a3f09dbc9263b1c5be89f60a15/optimize_later-0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "da862b3be5698a2535131a0e44f83cbf", "sha256": "6b81c6b5156c59f4e70fd5a7a9aef788f2bb7832482f7c4a25ff2c3812ba2ba4" }, "downloads": -1, "filename": "optimize-later-0.2.tar.gz", "has_sig": false, "md5_digest": "da862b3be5698a2535131a0e44f83cbf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8127, "upload_time": "2018-08-22T18:44:12", "url": "https://files.pythonhosted.org/packages/56/93/563571529cb7120cb2980d86551f403ce386cc3b756395263ed31f4755ae/optimize-later-0.2.tar.gz" } ] }