pytictoc


Namepytictoc JSON
Version 1.5.3 PyPI version JSON
download
home_pagehttps://github.com/ericcfields/pytictoc
SummaryTime code using syntax similar to tic and toc in MATLAB
upload_time2023-08-02 20:08:15
maintainer
docs_urlNone
authorEric Fields
requires_python
licenseBSD (three-clause)
keywords timing tic toc matlab
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            pytictoc contains a class TicToc which replicates the functionality of MATLAB's tic and toc for easily timing sections of code. Under the hood, pytictoc uses the default_timer function from Python's timeit module.

=============
INSTALLATION
=============

pytictoc can be installed and updated via conda or pip.

**pip** ::
 
  pip install pytictoc
  pip install pytictoc --upgrade

**conda** ::

  conda install pytictoc -c ecf
  conda update pytictoc -c ecf


=============
USAGE
============= 

Basic usage: ::

  >> from pytictoc import TicToc
  >> t = TicToc() #create instance of class

  >> t.tic() #Start timer
  >> t.toc() #Time elapsed since t.tic()
  Elapsed time is 2.612231 seconds.

A string passed to the toc method changes the printed message. This can be useful to differentiate timing of different sections in the same script. ::

  >> t.toc('Section 1 took')
  Section 1 took 16.494467 seconds.

An optional keyword argument restarts the timer (equivalent to t.tic()) after reporting the time elapsed. ::

  >> t.toc(restart=True)
  Elapsed time is 36.986837 seconds.
  >>t.toc()
  Elapsed time is 2.393425 seconds.

If you want to return the time elapsed to a variable rather than printing it, use the tocvalue method. ::

  >>spam = t.tocvalue()
  >>spam
  20.156261717544602

The TicToc class can be used within a context manager as an alternative way to time a section of code. The time taken to run the code inside the with statement will be reported on exit. ::
 
  >>with TicToc():
  >>    spam = [x+1 for x in range(10000)]
  Elapsed time is 0.002343 seconds.

------------------------------------
Determining and setting the timer
------------------------------------

pytictoc uses timeit.default_timer to time code. On Python 3.3 and later, this is an alias for time.perf_counter. On earlier versions of Python it is an alias for the most precise timer for a given system. 

To see which function is being used: ::

  >>import pytictoc
  >>pytictoc.default_timer
  <function time.perf_counter>

You can change the timer by simple assignment. ::
  
  >>import time
  >>pytictoc.default_timer = time.clock
  >>pytictoc.default_timer
  <function time.clock>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ericcfields/pytictoc",
    "name": "pytictoc",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "timing tic toc MATLAB",
    "author": "Eric Fields",
    "author_email": "fieldsec@westminster.edu",
    "download_url": "https://files.pythonhosted.org/packages/4c/be/7652410c5de4ab8a8fb16c52f824531ae8c697b13ca44b3ebbeac2cc005c/pytictoc-1.5.3.tar.gz",
    "platform": null,
    "description": "pytictoc contains a class TicToc which replicates the functionality of MATLAB's tic and toc for easily timing sections of code. Under the hood, pytictoc uses the default_timer function from Python's timeit module.\r\n\r\n=============\r\nINSTALLATION\r\n=============\r\n\r\npytictoc can be installed and updated via conda or pip.\r\n\r\n**pip** ::\r\n \r\n  pip install pytictoc\r\n  pip install pytictoc --upgrade\r\n\r\n**conda** ::\r\n\r\n  conda install pytictoc -c ecf\r\n  conda update pytictoc -c ecf\r\n\r\n\r\n=============\r\nUSAGE\r\n============= \r\n\r\nBasic usage: ::\r\n\r\n  >> from pytictoc import TicToc\r\n  >> t = TicToc() #create instance of class\r\n\r\n  >> t.tic() #Start timer\r\n  >> t.toc() #Time elapsed since t.tic()\r\n  Elapsed time is 2.612231 seconds.\r\n\r\nA string passed to the toc method changes the printed message. This can be useful to differentiate timing of different sections in the same script. ::\r\n\r\n  >> t.toc('Section 1 took')\r\n  Section 1 took 16.494467 seconds.\r\n\r\nAn optional keyword argument restarts the timer (equivalent to t.tic()) after reporting the time elapsed. ::\r\n\r\n  >> t.toc(restart=True)\r\n  Elapsed time is 36.986837 seconds.\r\n  >>t.toc()\r\n  Elapsed time is 2.393425 seconds.\r\n\r\nIf you want to return the time elapsed to a variable rather than printing it, use the tocvalue method. ::\r\n\r\n  >>spam = t.tocvalue()\r\n  >>spam\r\n  20.156261717544602\r\n\r\nThe TicToc class can be used within a context manager as an alternative way to time a section of code. The time taken to run the code inside the with statement will be reported on exit. ::\r\n \r\n  >>with TicToc():\r\n  >>    spam = [x+1 for x in range(10000)]\r\n  Elapsed time is 0.002343 seconds.\r\n\r\n------------------------------------\r\nDetermining and setting the timer\r\n------------------------------------\r\n\r\npytictoc uses timeit.default_timer to time code. On Python 3.3 and later, this is an alias for time.perf_counter. On earlier versions of Python it is an alias for the most precise timer for a given system. \r\n\r\nTo see which function is being used: ::\r\n\r\n  >>import pytictoc\r\n  >>pytictoc.default_timer\r\n  <function time.perf_counter>\r\n\r\nYou can change the timer by simple assignment. ::\r\n  \r\n  >>import time\r\n  >>pytictoc.default_timer = time.clock\r\n  >>pytictoc.default_timer\r\n  <function time.clock>\r\n",
    "bugtrack_url": null,
    "license": "BSD (three-clause)",
    "summary": "Time code using syntax similar to tic and toc in MATLAB",
    "version": "1.5.3",
    "project_urls": {
        "Homepage": "https://github.com/ericcfields/pytictoc"
    },
    "split_keywords": [
        "timing",
        "tic",
        "toc",
        "matlab"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa47a802641f9efe9f774902383e6ca8f75af5531a1cd71c6e738dcb2c84118c",
                "md5": "9545bb96c7134dec86e9c34f078a6e5b",
                "sha256": "df4547aa839f2e39f64e4aa0c4af3fe441e8cea6ecaecf239fb3f0daf1afc8cb"
            },
            "downloads": -1,
            "filename": "pytictoc-1.5.3-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9545bb96c7134dec86e9c34f078a6e5b",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 4050,
            "upload_time": "2023-08-02T20:08:12",
            "upload_time_iso_8601": "2023-08-02T20:08:12.855761Z",
            "url": "https://files.pythonhosted.org/packages/fa/47/a802641f9efe9f774902383e6ca8f75af5531a1cd71c6e738dcb2c84118c/pytictoc-1.5.3-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4cbe7652410c5de4ab8a8fb16c52f824531ae8c697b13ca44b3ebbeac2cc005c",
                "md5": "6f5faf5f7dcd5854268e236d1bf45651",
                "sha256": "0722acd1ea60d8de31e7babeb11200d04067f94e7dece5e86e16ffd2eb7940cf"
            },
            "downloads": -1,
            "filename": "pytictoc-1.5.3.tar.gz",
            "has_sig": false,
            "md5_digest": "6f5faf5f7dcd5854268e236d1bf45651",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4984,
            "upload_time": "2023-08-02T20:08:15",
            "upload_time_iso_8601": "2023-08-02T20:08:15.354432Z",
            "url": "https://files.pythonhosted.org/packages/4c/be/7652410c5de4ab8a8fb16c52f824531ae8c697b13ca44b3ebbeac2cc005c/pytictoc-1.5.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-02 20:08:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ericcfields",
    "github_project": "pytictoc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pytictoc"
}
        
Elapsed time: 1.26133s