Skip to content

Commit 7005fa0

Browse files
authored
Merge pull request #1943 from codeflash-ai/codeflash/optimize-pr1941-2026-04-01T14.15.33
⚡️ Speed up function `fmt_delta` by 11% in PR #1941 (`cf-compare-copy-benchmarks`)
2 parents 3e19151 + e670bf4 commit 7005fa0

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

codeflash/benchmarking/compare.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
from codeflash.models.function_types import FunctionToOptimize
3030
from codeflash.models.models import BenchmarkKey
3131

32+
_GREEN_TPL = "[green]%+.0f%%[/green]"
33+
34+
_RED_TPL = "[red]%+.0f%%[/red]"
35+
3236

3337
@dataclass
3438
class CompareResult:
@@ -609,8 +613,8 @@ def fmt_delta(before: Optional[float], after: Optional[float]) -> str:
609613
return "-"
610614
pct = ((after - before) / before) * 100 if before != 0 else 0
611615
if pct < 0:
612-
return f"[green]{pct:+.0f}%[/green]"
613-
return f"[red]{pct:+.0f}%[/red]"
616+
return _GREEN_TPL % pct
617+
return _RED_TPL % pct
614618

615619

616620
def md_speedup(before: Optional[float], after: Optional[float]) -> str:

0 commit comments

Comments
 (0)