This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Picker: Perf test; Cache e-series (#41)
- Loading branch information
1 parent
d82e61e
commit 1437458
Showing
5 changed files
with
142 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# This file is part of the faebryk project | ||
# SPDX-License-Identifier: MIT | ||
|
||
import time | ||
from textwrap import indent | ||
|
||
|
||
class Times: | ||
def __init__(self) -> None: | ||
self.times = {} | ||
self.last_time = time.time() | ||
|
||
def add(self, name: str): | ||
now = time.time() | ||
if name not in self.times: | ||
self.times[name] = now - self.last_time | ||
self.last_time = now | ||
|
||
def _format_val(self, val: float): | ||
return f"{val * 1000:.2f}ms" | ||
|
||
def __repr__(self): | ||
formatted = { | ||
k: self._format_val(v) | ||
for k, v in self.times.items() | ||
if not k.startswith("_") | ||
} | ||
longest_name = max(len(k) for k in formatted) | ||
return "Timings: \n" + indent( | ||
"\n".join(f"{k:>{longest_name}}: {v:<10}" for k, v in formatted.items()), | ||
" " * 4, | ||
) | ||
|
||
class Context: | ||
def __init__(self, name: str, times: "Times"): | ||
self.name = name | ||
self.times = times | ||
|
||
def __enter__(self): | ||
self.times.add("_" + self.name) | ||
self.start = time.time() | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
self.times.times[self.name] = time.time() - self.start | ||
|
||
def context(self, name: str): | ||
return Times.Context(name, self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters