{ "info": { "author": "ianlini", "author_email": "", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Utilities" ], "description": "Please visit the `GitHub repository `_\nfor more information.\n\nBisTiming\n=========\n.. image:: https://img.shields.io/travis/ianlini/bistiming/master.svg\n :target: https://travis-ci.org/ianlini/bistiming\n.. image:: https://readthedocs.org/projects/pip/badge/\n :target: https://bistiming.readthedocs.io/\n.. image:: https://img.shields.io/pypi/v/bistiming.svg\n :target: https://pypi.org/project/bistiming/\n.. image:: https://img.shields.io/pypi/l/bistiming.svg\n :target: https://github.com/ianlini/bistiming/blob/master/LICENSE\n.. image:: https://img.shields.io/github/stars/ianlini/bistiming.svg?style=social\n :target: https://github.com/ianlini/bistiming\n\nA logging-friendly stopwatch and profiling tool for Python.\n\nWhen we search the stopwatch or timing module for Python on the internet, we can find a\nlot of code snippets, but none of them is powerful or convenient enough to do our daily\njobs.\nBisTiming aims at implementing all the missing functions in those code snippets and\npreventing us from reinventing the wheel.\nIt is very useful when we want to log something with some timing information or even\noptimize the performance of our code.\n\nThis package is tested with Python 2.7, 3.5, 3.6 and 3.7, but may also work in other\nPython versions.\n\n.. contents::\n\nInstallation\n------------\n.. code:: bash\n\n pip install bistiming\n\nGetting Started\n---------------\n\nBisTiming has a context manager interface that let us log the running time of a code block\neasily, and it also has low-level API that let us time multiple segments or loops of\ncode easily.\n\nSee `examples `_\nfor all the useful examples.\n\nContext Manager\n+++++++++++++++\n\nThe simplest way to use BisTiming is using the context manager ``Stopwatch``\nto include the code we want to evaluate:\n\n>>> from bistiming import Stopwatch\n>>> from time import sleep\n>>> with Stopwatch(\"Waiting\"):\n... print(\"do something\")\n... sleep(0.1)\n... print(\"finished something\")\n...\n...Waiting\ndo something\nfinished something\n...Waiting done in 0:00:00.100330\n\nWe can use the parameter `logger` and `logging_level` to tell the stopwatch to output\nusing a logger:\n\n>>> import logging\n>>> logging.basicConfig(\n... level=logging.DEBUG,\n... format=\"[%(asctime)s] %(levelname)s: %(name)s: %(message)s\")\n>>> logger = logging.getLogger(__name__)\n>>> with Stopwatch(\"Waiting\", logger=logger, logging_level=logging.DEBUG):\n... print(\"do something\")\n... sleep(0.1)\n... print(\"finished something\")\n...\n[2019-04-24 22:27:52,347] DEBUG: __main__: ...Waiting\ndo something\nfinished something\n[2019-04-24 22:27:52,448] DEBUG: __main__: ...Waiting done in 0:00:00.100344\n\nAnother common use case is to evaluate the running time of a specific code segment\nin a loop, we can initialize the stopwatch outside the loop, and reuse it in the loop:\n\n>>> timer = Stopwatch(\"Waiting\")\n>>> for i in range(2):\n... with timer:\n... print(\"do something 1\")\n... sleep(0.1)\n... print(\"finished something 1\")\n... print(\"do something 2\")\n... sleep(0.1)\n... print(\"finished something 2\")\n...\n...Waiting\ndo something 1\nfinished something 1\n...Waiting done in 0:00:00.100468\ndo something 2\nfinished something 2\n...Waiting\ndo something 1\nfinished something 1\n...Waiting done in 0:00:00.100440\ndo something 2\nfinished something 2\n>>> timer.split_elapsed_time\n[datetime.timedelta(microseconds=100468),\n datetime.timedelta(microseconds=100440)]\n>>> timer.get_cumulative_elapsed_time()\ndatetime.timedelta(microseconds=200908)\n\nEach item in ``split_elapsed_time`` is the running time of\nthe code segment in each iteration, and we can use\n``get_cumulative_elapsed_time()``\nto get the total running time of the code segment.\n\nLow-level API\n+++++++++++++\nThe low-level API is similar to a stopwatch in real life.\nA simple use case using the low-level API is:\n\n>>> from time import sleep\n>>> from bistiming import Stopwatch\n>>> timer = Stopwatch(\"Waiting\").start()\n...Waiting\n>>> sleep(0.2) # do the first step of my program\n>>> timer.split()\n...Waiting done in 0:00:00.201457\n>>> sleep(0.1) # do the second step of my program\n>>> timer.split()\n...Waiting done in 0:00:00.100982\n\nThe context manager\n\n>>> with Stopwatch(\"Waiting\"):\n... sleep(0.1)\n...Waiting\n...Waiting done in 0:00:00.100330\n\nis actually equivalent to the low-level API:\n\n>>> timer = Stopwatch(\"Waiting\").start()\n...Waiting\n>>> sleep(0.1)\n>>> timer.pause()\n>>> timer.split()\n...Waiting done in 0:00:00.100330\n\nAdvance Profiling\n+++++++++++++++++\n``MultiStopwatch`` in this package contains multiple\n``Stopwatch``, so we can use them to define each code segment\nwe want to evaluate and compare easily:\n\n>>> from time import sleep\n>>> from bistiming import MultiStopwatch\n>>> timers = MultiStopwatch(2, verbose=False)\n>>> for i in range(5):\n... for i in range(2):\n... with timers[0]:\n... sleep(0.1)\n... with timers[1]:\n... sleep(0.1)\n...\n>>> timers.get_statistics()\n{'cumulative_elapsed_time': [datetime.timedelta(seconds=1, microseconds=2879),\n datetime.timedelta(microseconds=501441)],\n 'percentage': [0.6666660019144863, 0.3333339980855137],\n 'n_splits': [10, 5],\n 'mean_per_split': [datetime.timedelta(microseconds=100288),\n datetime.timedelta(microseconds=100288)]}\n\nWe can also use ``pandas.DataFrame`` to make the statistics more readable\n(note that you may need to\n`install pandas `_ first):\n\n>>> import pandas as pd\n>>> pd.DataFrame(timers.get_statistics())\n cumulative_elapsed_time percentage n_splits mean_per_split\n0 00:00:01.002879 0.666666 10 00:00:00.100288\n1 00:00:00.501441 0.333334 5 00:00:00.100288\n\nDocumentation\n-------------\nThere are a lot more ways to use this package.\nSee the `documentation `_ for more information.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ianlini/bistiming", "keywords": "", "license": "BSD 2-Clause", "maintainer": "", "maintainer_email": "", "name": "bistiming", "package_url": "https://pypi.org/project/bistiming/", "platform": "", "project_url": "https://pypi.org/project/bistiming/", "project_urls": { "Homepage": "https://github.com/ianlini/bistiming" }, "release_url": "https://pypi.org/project/bistiming/0.4.0/", "requires_dist": [ "six" ], "requires_python": "", "summary": "A logging-friendly stopwatch and profiling tool for Python.", "version": "0.4.0" }, "last_serial": 5199527, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "9739d570f429a37e50ec2950daaa9fce", "sha256": "a18179a8ebe7e5d8c68a90308d2cbbb531d0fc364f8d2af34aadbb08755cbef0" }, "downloads": -1, "filename": "bistiming-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "9739d570f429a37e50ec2950daaa9fce", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 3978, "upload_time": "2016-10-17T16:12:18", "url": "https://files.pythonhosted.org/packages/ae/8b/da178a72d2ed918da40f225de15321b3141a19f9e8a8d61e44dac98aba41/bistiming-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5308f00ce5a2a3acfe53cdcb99048cfc", "sha256": "f57026d6c2368e9d7e387ec6322880933d3ce62c24cadffa7d47b0f3bcbb7038" }, "downloads": -1, "filename": "bistiming-0.1.0.tar.gz", "has_sig": false, "md5_digest": "5308f00ce5a2a3acfe53cdcb99048cfc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2601, "upload_time": "2016-10-17T16:12:21", "url": "https://files.pythonhosted.org/packages/b4/22/39abd62e85883338979deda587145f137b8bff45844dcd7ea21840025d73/bistiming-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "2fbd509dfe91738a51539ebe7ef35a87", "sha256": "e8bd0aa748838df38f50296b008b2e0e799b4be491f801808d12aa20ec73d872" }, "downloads": -1, "filename": "bistiming-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "2fbd509dfe91738a51539ebe7ef35a87", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 4075, "upload_time": "2016-12-02T16:08:24", "url": "https://files.pythonhosted.org/packages/cf/8b/8a47ef51ffd41f39bf94782e7dae6fd42e0df00f8d2603217b6222ccb596/bistiming-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "06890b2248357d9541872b8fcb1b0f60", "sha256": "2f3684827a7610f6cafed0eb502c296c0d95ef324c966124f04d6fd0998cddec" }, "downloads": -1, "filename": "bistiming-0.1.1.tar.gz", "has_sig": false, "md5_digest": "06890b2248357d9541872b8fcb1b0f60", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2653, "upload_time": "2016-12-02T16:08:27", "url": "https://files.pythonhosted.org/packages/1d/ce/263977381bd95220358930991260430bab607c224516765bf09d5beaff3e/bistiming-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "5292a6b09a6db9381298660a4f466afe", "sha256": "960b14285cf0b68ef34e2edf50610c301151c6e77d5951c1b4117d433242ad40" }, "downloads": -1, "filename": "bistiming-0.2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5292a6b09a6db9381298660a4f466afe", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 4633, "upload_time": "2019-04-17T16:53:46", "url": "https://files.pythonhosted.org/packages/f8/4f/96a7c04e6a1b8b04991fe81aa91f5573c783fca33f7ef89d2f0f2dd2702f/bistiming-0.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1afc9138adadac4466dbf96fa15fb9d0", "sha256": "6d8c68e2f1d693802727f3efd0441b6a1ec275fdd1d9ab9b7a7540850501beb5" }, "downloads": -1, "filename": "bistiming-0.2.0.tar.gz", "has_sig": false, "md5_digest": "1afc9138adadac4466dbf96fa15fb9d0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3625, "upload_time": "2019-04-17T16:53:47", "url": "https://files.pythonhosted.org/packages/fe/4d/c21dc29f923e4d390f6f73922f0113f0e8baf8ee8f505bbd58e5af0753d2/bistiming-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "271cd921499d54afc6e6d4a9a47f79ab", "sha256": "40dd9ebe6d2394e0f7b4739abd58f69973aa004a18cb0897f4c2c7314ac16f6c" }, "downloads": -1, "filename": "bistiming-0.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "271cd921499d54afc6e6d4a9a47f79ab", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7943, "upload_time": "2019-04-24T17:58:05", "url": "https://files.pythonhosted.org/packages/2f/a1/530f4f40ed93f189dd1eff8cd67e537c7c26e3b3700d7b2429506c22e695/bistiming-0.3.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1cf6007807b75c9b1bbe087eaa7d143a", "sha256": "698af183588b82eb08a7829d0db49b63b8b1f5c3361a12d8d3918e5a7f483277" }, "downloads": -1, "filename": "bistiming-0.3.0.tar.gz", "has_sig": false, "md5_digest": "1cf6007807b75c9b1bbe087eaa7d143a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8677, "upload_time": "2019-04-24T17:58:07", "url": "https://files.pythonhosted.org/packages/3b/2d/0d358cf643b94b57586879689c791dd309b62b9b3809e5372124473c3ca6/bistiming-0.3.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "05611d02ebf48ddd0fc38848435ef242", "sha256": "81b1d6da07116dce30bf068296e3f52dffcb7711a038394453f851468ec175b3" }, "downloads": -1, "filename": "bistiming-0.4.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "05611d02ebf48ddd0fc38848435ef242", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9744, "upload_time": "2019-04-28T11:55:57", "url": "https://files.pythonhosted.org/packages/f3/b7/658fd2eb50baf0de6f1a2c4f325f5207267008875949c5db3b357341dedb/bistiming-0.4.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "77315075a76f7de416e3d77d65b09904", "sha256": "75ec20dd23c47e0d095f70acb70ff25c1620e16247d8889c8aafcd50227d81ad" }, "downloads": -1, "filename": "bistiming-0.4.0.tar.gz", "has_sig": false, "md5_digest": "77315075a76f7de416e3d77d65b09904", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8371, "upload_time": "2019-04-28T11:56:01", "url": "https://files.pythonhosted.org/packages/ea/64/efdaafd28e76f8143c6a7cc8b7437dc8af5ca29e77d8866e5002f553a7fd/bistiming-0.4.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "05611d02ebf48ddd0fc38848435ef242", "sha256": "81b1d6da07116dce30bf068296e3f52dffcb7711a038394453f851468ec175b3" }, "downloads": -1, "filename": "bistiming-0.4.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "05611d02ebf48ddd0fc38848435ef242", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 9744, "upload_time": "2019-04-28T11:55:57", "url": "https://files.pythonhosted.org/packages/f3/b7/658fd2eb50baf0de6f1a2c4f325f5207267008875949c5db3b357341dedb/bistiming-0.4.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "77315075a76f7de416e3d77d65b09904", "sha256": "75ec20dd23c47e0d095f70acb70ff25c1620e16247d8889c8aafcd50227d81ad" }, "downloads": -1, "filename": "bistiming-0.4.0.tar.gz", "has_sig": false, "md5_digest": "77315075a76f7de416e3d77d65b09904", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8371, "upload_time": "2019-04-28T11:56:01", "url": "https://files.pythonhosted.org/packages/ea/64/efdaafd28e76f8143c6a7cc8b7437dc8af5ca29e77d8866e5002f553a7fd/bistiming-0.4.0.tar.gz" } ] }