Skip to content

Commit

Permalink
Don't crash on fast calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed May 12, 2024
1 parent ba531b5 commit ba826bf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
4 changes: 2 additions & 2 deletions bw_aggregation/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from bw2calc import LCA
from bw2data import Database, prepare_lca_inputs

from .calculator import AggregationCalculator
from .override import AggregationContext


Expand All @@ -27,7 +26,8 @@ def difference(self) -> Speedup:
with_ = self.calculate_with_speedup()
return Speedup(
database_name=self.name,
time_difference_relative=with_ / without,
# Timer on Windows is coarse, could be zero for small databases
time_difference_relative=(with_ / without if without > 0 else 0),
time_difference_absolute=with_ - without,
time_with_aggregation=with_,
time_without_aggregation=without,
Expand Down
9 changes: 2 additions & 7 deletions tests/test_estimation.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import sys

import pytest

from bw_aggregation import AggregatedDatabase, Speedup


@pytest.mark.skipif(
sys.platform.startswith("win"),
reason="Windows `time` function has too low resolution",
)
def test_speedup_estimate(background):
speedup = AggregatedDatabase.estimate_speedup("a")
assert isinstance(speedup, Speedup)
assert speedup.time_difference_relative < 1
if not sys.platform.startswith("win"):
assert speedup.time_difference_relative < 1

0 comments on commit ba826bf

Please sign in to comment.