Package: py-tictoc-timer
py-tictoc-timerTime the execution of Python code using syntax similar to MATLAB's tic and toc functions.Contentspy-tictoc-timerInstallationUsageContributionTestsCreditMaintainersInstallationUsingpip:pipinstallpy-tictoc-timerUsingpipenv:pipenvinstallpy-tictoc-timerUsingpoetry:In yourpyproject.tomlfile, add:[tool.poetry.dependencies]py-tictoc-timer="*"Then in the terminal, run:poetryinstallOr run:poetryaddpy-tictoc-timerUsingconda:condainstallpy-tictoc-timerUsageBasic usage:>>>frompy_tictoc_timer.tictocimportTicToc>>>fromtimeimportsleep>>>tt=TicToc()>>>tt.tic()>>>sleep(1.1)>>>tt.toc()Elapsedtime:1secsWithin context manager:>>>frompy_tictoc_timer.tictocimportTicToc>>>fromtimeimportsleep>>>withTicToc():...sleep(1.1)Elapsedtime:1secsWithin context manager using custom messages:>>>frompy_tictoc_timer.tictocimportTicToc>>>fromtimeimportsleep>>>withTicToc(begin_message="start",end_message="end"):...sleep(1.1)startend:1secsParticularly helpful when running loops:>>>frompy_tictoc_timer.tictocimportTicToc>>>fromtimeimportsleep>>>withTicToc(begin_message="Start loop",end_message="Time to run loop")...forvaluein["first","second","Third"]:...withTicToc(f"- Time for{value}"):...sleep(1.1)Startloop-Timeforfirst:1secs-Timeforsecond:1secs-TimeforThird:1secsTimetorunloop:3secsCustom message:>>>frompy_tictoc_timer.tictocimportTicToc>>>fromtimeimportsleep>>>withTicToc("Total Time"):...sleep(1.1)Totaltime:1secsWith restart during.tic():>>>frompy_tictoc_timer.tictocimportTicToc>>>fromtimeimportsleep>>>tt=TicToc()>>>tt.tic(restart=True)>>>sleep(1.1)>>>toc()Elapsedtime:1secs>>>toc()Elapsedtime:1secsWith restart during.toc():>>>frompy_tictoc_timer.tictocimportTicToc>>>fromtimeimportsleep>>>tt=TicToc()>>>tt.tic()>>>sleep(1.1)>>>tt.toc(restart=True)Elapsedtime:1secs>>>tt.toc()Elapsedtime:1secsWith restart using.rtoc():>>>frompy_tictoc_timer.tictocimportTicToc>>>fromtimeimportsleep>>>tt=TicToc()>>>tt.tic()>>>sleep(1.1)>>>tt.rtoc()Elapsedtime:1secs>>>tt.toc()Elapsedtime:1secsWith time returned as value:>>>frompy_tictoc_timer.tictocimportTicToc>>>fromtimeimportsleep>>>tt=TicToc()>>>tt.tic()>>>sleep(1.1)>>>value=tt.toc_value()>>>print(round(value,1))1.1With time returned as string:>>>frompy_tictoc_timer.tictocimportTicToc>>>fromtimeimportsleep>>>tt=TicToc()>>>tt.tic()>>>sleep(1.1)>>>value=tt.toc_string()>>>print(value)1secsContributionContribution is always welcome!First, eitherforkorbranchthemain repo.Cloneyour forked/branched repo.Build your environment with any of the below options:Withpipenv:if(-not(Test-Path.venv)){mkdir.venv}python-mpipenvinstall--requirementsrequirements.txt--ignore-pipfile--skip-lock--no-site-packages
python-mpipenvinstall--requirementsrequirements-dev.txt--dev--ignore-pipfile--skip-lock--no-site-packages
python-mpipenvrunpre-commitinstallWithpoetryon Windows:(Invoke-WebRequest-Urihttps://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py-UseBasicParsing).Content|python-
python-mpoetryrunpre-commitinstallWithpoetryon Linux:curl-sSLhttps://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py|python-
python-mpoetryrunpre-commitinstallStart contributing.Ensure you add additionalUnit Test's to thetest libraryfor each new feature/functionality.Ensure that all thetestsare passing successfully.When you're happy with the changes, raise aPull Requestto merge with themainbranch again.TestsRunBlack:pipenvrunpython-mblack--safepy_tictoc_timertestsRunPyTests:pipenvrunpython-mpytest--verbose--cov=py_tictoc_timer--cov-report=term--cov-report=html:cov-report/html--cov-report=xml:cov-report/xml/cov-report.xmlRunMyPyTests:pipenvrunmypypy_tictoc_timer--ignore-missing-imports--pretty--install-types--non-interactiveCreditThis package was inspired by a few other packages:pytictocTicTocTimerttictoceasy-tictoceasy-tic-toctictoc-borisgorelikWhy you should usepy-tictoc-timerand not any of the others is because this package has:Better & more flexible restart to the timerBetter custom messages during starting & ending the timerEnhanced usage within a context managerMaintainers