Skip to content

Commit 21fea6a

Browse files
Acuspeedsterpre-commit-ci[bot]tianyizheng02cclauss
authored
feat(timing): enhance timing function with adaptive units and run averaging (#11834)
* feat: add Matrix Exponentiation method docs: updated the header documentation and added new documentation for the new function. * feat: added new function matrix exponetiation method * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * feat: This function uses the tail-recursive form of the Euclidean algorithm to calculate * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * reduced the number of characters per line in the comments * removed unwanted code * feat: Implemented a new function to swaap numbers without dummy variable * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * removed previos code * Done with the required changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Done with the required changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Done with the required changes * Done with the required changes * Done with the required changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update maths/fibonacci.py Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Done with the required changes * Done with the required changes * Done with the required changes * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * feat(timing): enhance timing function with adaptive units and run averaging * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * feat(timing): enhance timing function with adaptive units and run averaging --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com> Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent da48fb8 commit 21fea6a

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

maths/fibonacci.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,20 @@ def time_func(func, *args, **kwargs):
2929
"""
3030
start = time()
3131
output = func(*args, **kwargs)
32-
end = time()
33-
if int(end - start) > 0:
34-
print(f"{func.__name__} runtime: {(end - start):0.4f} s")
32+
duration = time() - start
33+
34+
# Adjust the output unit based on the time taken
35+
if duration >= 1:
36+
unit = "s"
37+
time_taken = duration
38+
elif duration >= 0.001:
39+
unit = "ms"
40+
time_taken = duration * 1000
3541
else:
36-
print(f"{func.__name__} runtime: {(end - start) * 1000:0.4f} ms")
42+
unit = "µs"
43+
time_taken = duration * 1_000_000
44+
45+
print(f"{func.__name__} runtime: {time_taken:0.4f} {unit}")
3746
return output
3847

3948

0 commit comments

Comments
 (0)