cengal.time_management.run_time.versions.v_0.run_time

 1#!/usr/bin/env python
 2# coding=utf-8
 3
 4# Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>
 5# 
 6# Licensed under the Apache License, Version 2.0 (the "License");
 7# you may not use this file except in compliance with the License.
 8# You may obtain a copy of the License at
 9# 
10#     http://www.apache.org/licenses/LICENSE-2.0
11# 
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18
19__all__ = ['RunTime', 'RT']
20
21
22"""
23Module Docstring
24Docstrings: http://www.python.org/dev/peps/pep-0257/
25"""
26
27__author__ = "ButenkoMS <gtalk@butenkoms.space>"
28__copyright__ = "Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>"
29__credits__ = ["ButenkoMS <gtalk@butenkoms.space>", ]
30__license__ = "Apache License, Version 2.0"
31__version__ = "4.4.1"
32__maintainer__ = "ButenkoMS <gtalk@butenkoms.space>"
33__email__ = "gtalk@butenkoms.space"
34# __status__ = "Prototype"
35__status__ = "Development"
36# __status__ = "Production"
37
38
39from cengal.time_management.cpu_clock_cycles import perf_counter
40from cengal.math.numbers import RationalNumber
41
42
43class RunTime:
44    def __init__(self) -> None:
45        self.start_time: RationalNumber = None
46        self.end_time: RationalNumber = None
47        self._run_time: RationalNumber = None
48        self.success: bool = None
49    
50    def __enter__(self):
51        self.start_time = perf_counter()
52        return self
53
54    def __exit__(self, exc_type, exc_val, exc_tb):
55        self.end_time = perf_counter()
56        self._run_time = self.end_time - self.start_time
57        self.success = (exc_type is None) and (exc_val is None) and (exc_tb is None)
58        return False
59    
60    def __bool__(self):
61        return self.success
62    
63    @property
64    def run_rime(self):
65        return self._run_time
66    
67    @property
68    def rt(self):
69        return self._run_time
70
71
72RT = RunTime
class RunTime:
44class RunTime:
45    def __init__(self) -> None:
46        self.start_time: RationalNumber = None
47        self.end_time: RationalNumber = None
48        self._run_time: RationalNumber = None
49        self.success: bool = None
50    
51    def __enter__(self):
52        self.start_time = perf_counter()
53        return self
54
55    def __exit__(self, exc_type, exc_val, exc_tb):
56        self.end_time = perf_counter()
57        self._run_time = self.end_time - self.start_time
58        self.success = (exc_type is None) and (exc_val is None) and (exc_tb is None)
59        return False
60    
61    def __bool__(self):
62        return self.success
63    
64    @property
65    def run_rime(self):
66        return self._run_time
67    
68    @property
69    def rt(self):
70        return self._run_time
start_time: Union[int, float]
end_time: Union[int, float]
success: bool
run_rime
64    @property
65    def run_rime(self):
66        return self._run_time
rt
68    @property
69    def rt(self):
70        return self._run_time
RT = <class 'RunTime'>