Skip to content

Commit e3bd987

Browse files
committed
A possible temporary solution to benchmark
Signed-off-by: Maria Teresa Ortega <teresa.ortega0903@gmail.com>
1 parent c858ed6 commit e3bd987

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

src/lambkin/core/decorators/benchmark.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ def wrapper(args=None, output_dir=None):
8484
cli_args = sys.argv[1:] if args is None else args
8585
options = _parse_options(fn, cli_args)
8686
source = Source(path=inspect.getfile(fn))
87+
base_ctx = Context(
88+
variant={},
89+
iteration=0,
90+
options=options,
91+
source=source,
92+
variant_index=0,
93+
output_dir=output_dir,
94+
)
95+
inputs.resolve(base_ctx)
96+
resolved_inputs = base_ctx.inputs
8797
for variant_index, variant in enumerate(variants):
8898
for iteration in range(num_iterations):
8999
ctx = Context(
@@ -94,7 +104,7 @@ def wrapper(args=None, output_dir=None):
94104
variant_index=variant_index,
95105
output_dir=output_dir,
96106
)
97-
inputs.resolve(ctx)
107+
ctx.inputs = resolved_inputs
98108
fn(ctx)
99109

100110
wrapper.input = inputs.register

test/core/test_input.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,3 @@ def map(ctx):
9999

100100
nominal(output_dir="/tmp")
101101
assert seen == [("path/to/dataset.mcap", "path/to/map.yaml")]
102-
103-
104-
def test_inputs_resolved_on_every_iteration(variant):
105-
"""resolve() must run once per iteration, not just once upfront."""
106-
call_count = [0]
107-
seen = []
108-
109-
@benchmark(variants=variant, num_iterations=3)
110-
def nominal(ctx):
111-
seen.append(ctx.inputs.counter)
112-
113-
@nominal.input
114-
def counter(ctx):
115-
call_count[0] += 1
116-
return call_count[0]
117-
118-
nominal(output_dir="/tmp")
119-
120-
assert seen == [1, 2, 3]

0 commit comments

Comments
 (0)