File: test_timing.py

package info (click to toggle)
python-ase 3.26.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,484 kB
  • sloc: python: 148,112; xml: 2,728; makefile: 110; javascript: 47
file content (29 lines) | stat: -rw-r--r-- 486 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# fmt: off
import time

from ase.utils.timing import Timer, timer


class A:
    def __init__(self):
        self.timer = Timer()

    @timer('run')
    def run(self):
        for i in self.yielding():
            print(i)

    @timer('yield')
    def yielding(self):
        for i in range(5):
            time.sleep(0.001)
            yield i


def test_timer():
    a = A()
    a.run()
    a.timer.write()
    t = a.timer.timers
    ty = t[('run', 'yield')]
    assert ty > 0.005, t