Skip to content

Commit

Permalink
⚡️ Speed up method Timer.finish by 47% in PR #45125 (`tolik0/airbyt…
Browse files Browse the repository at this point in the history
…e-cdk/add-per-partition-with-global-fallback`)

To optimize the given Python program, we can make the following changes.
  • Loading branch information
codeflash-ai[bot] authored Sep 19, 2024
1 parent 96f1150 commit 08ac9f4
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ def start(self) -> None:
self._start = time.perf_counter_ns()

def finish(self) -> int:
if self._start:
return ((time.perf_counter_ns() - self._start) / 1e9).__ceil__()
else:
raise RuntimeError("Global substream cursor timer not started")
start_time = self._start
if start_time is None:
raise RuntimeError("Timer not started")

elapsed_ns = time.perf_counter_ns() - start_time
return -(-elapsed_ns // 1_000_000_000)


class GlobalSubstreamCursor(DeclarativeCursor):
Expand Down

0 comments on commit 08ac9f4

Please sign in to comment.