1Metadata-Version: 2.1
2Name: ttictoc
3Version: 0.5.6
4Summary: Time parts of your code easily.
5Home-page: https://github.com/hector-sab/ttictoc
6Author: Hector Sanchez
7Author-email: hector.direct@gmail.com
8License: MIT
9Description: # ttictoc
10        Time execution of blocks of code.
11
12        ##
13        Tested against python 3.6, python 3.7, and 3.8
14
15        ## How to install
16        From pip
17        ```
18        pip install ttictoc
19        ```
20        or download this repo and do
21        ```
22        pip install .
23        ```
24
25        ## TicToc
26        The easiest way to time something is with `tic` and `toc`
27
28        ```python
29        import time
30        from ttictoc import tic,toc
31        tic()
32        time.sleep(1)
33        elapsed = toc()
34        print('Elapsed time:',elapsed)
35        ```
36
37        You can execute multiple tocs in a matlab-like fashon
38        ```
39        import time
40        from ttictoc import tic,toc
41        tic()
42        for i in range(2):
43          tic()
44          time.sleep(1)
45          elapsed = toc()
46          print('[IN LOOP] Elapsed time:',elapsed)
47        print('[OUT LOOP] Elapsed time:',toc())
48        ```
49
50        ## Timer Class
51        It works just like `tic`,`toc`.
52        ```python
53        import time
54        from ttictoc import Timer
55
56        # Simple
57        t = Timer()
58        t.start()
59        time.sleep(1)
60        elapsed = t.stop()
61        print('Elapsed time:',elapsed)
62
63
64        # Nested
65        t.start()
66        for i in range(2):
67          t.start()
68          time.sleep(1)
69          elapsed = t.stop()
70          print('[IN LOOP] Elapsed time:',elapsed)
71        print('[OUT LOOP] Elapsed time:',t.stop())
72        ```
73
74        ## Context manager
75        You can also use it as context manager
76        ```python
77        import time
78        from ttictoc import Timer
79
80        # Default
81        with Timer():
82          time.sleep(1)
83
84        # With out verbose
85        with Timer(verbose=False) as T:
86          time.sleep(1)
87        print('Elapsed time:',T.elapsed)
88
89        # With default verbose message
90        with Timer(verbose_msg=f'[User msg][{time.time()}] Elapsed time: {{}}'):
91          time.sleep(1)
92        ```
93
94        ## Deactivating matlab-like nesting
95        You can deactivate the matlab-like nesting. In this case calling start will update the global starting time for toc. However, you can have nested tics by giving a `key` to start and stop.
96        ```python
97        import time
98        from ttictoc import Timer,tic2,toc2
99
100        tic2()
101        for i in range(2):
102          tic2()
103          time.sleep(1)
104          elapsed = toc2()
105          print('[IN LOOP] Elapsed time:',elapsed)
106        print('[OUT LOOP] Elapsed time:',toc2())
107
108        t = Timer(matlab_like=False)
109        t.start()
110        time.sleep(1)
111        t.start() # Restarts the starting point
112        time.sleep(1)
113        elapsed = t.stop()
114        print('Elapsed time:',elapsed) # ~1 second
115
116        # Nested
117        t.start(key='Init')
118        for i in range(2):
119          t.start(key=i)
120          time.sleep(1)
121          elapsed = t.stop(key=i)
122          print('[IN LOOP] Elapsed time:',elapsed)
123        print('[OUT LOOP] Elapsed time:',t.stop('Init'))
124
125
126        print('\n[OUT LOOP][Init] Elapsed time:',t.stop('Init'))
127        print('[OUT LOOP][0] Elapsed time:',t.stop(0))
128        print('[OUT LOOP][1] Elapsed time:',t.stop(1))
129        ```
130
131        ## Specify timing method
132        By default, `Timer` (and `tic`,`toc`) use `timeit.default_timer`. However, the timing function can be selected as follow.
133        ```python
134        import time
135        from ttictoc import Timer
136        t = Timer(func_time=time.clock)
137        t.start()
138        time.sleep(5)
139        elapsed = t.stop()
140        print('Elapsed time:',elapsed)
141        ```
142
143Keywords: tictoc tic toc time timing
144Platform: UNKNOWN
145Classifier: Programming Language :: Python
146Classifier: Programming Language :: Python :: 2.7
147Classifier: Programming Language :: Python :: 3
148Classifier: Programming Language :: Python :: 3.3
149Classifier: Programming Language :: Python :: 3.4
150Classifier: Programming Language :: Python :: 3.5
151Classifier: Programming Language :: Python :: 3.6
152Classifier: License :: OSI Approved :: MIT License
153Classifier: Operating System :: OS Independent
154Description-Content-Type: text/markdown
155