Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] BenchConfig arguments in Bench seem to have no effect #3802

Open
samufi opened this issue Nov 23, 2024 · 1 comment
Open

[BUG] BenchConfig arguments in Bench seem to have no effect #3802

samufi opened this issue Nov 23, 2024 · 1 comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@samufi
Copy link

samufi commented Nov 23, 2024

Bug description

When benchmarking a simple function, the constraints set as arguments of BenchConfig, handed over to Bench seem not to have an effect. On my machine, the benchmarking does not halt in reasonable time. (I have not observed the program to stop at all, but I have not waited longer than 30s)

Steps to reproduce

Reproduce via the following code:

import random
from benchmark import Bencher, keep, Bench, BenchId, BenchConfig


fn expensive_fn() -> Int:
    var s = 0
    for _ in range(100):
        s += int(random.random_float64() < 0.5)
    return s


fn benchmark_fun(inout bencher: Bencher) capturing:
    @always_inline
    @parameter
    fn bench_fn(calls: Int) capturing -> Int:
        for _ in range(calls):
            keep(expensive_fn()) 
        return calls

    bencher.iter_custom[bench_fn]()
 
def main():
    config = BenchConfig(max_runtime_secs=3, max_iters=3)
    bench = Bench(config)
    bench.bench_function[benchmark_fun](BenchId("my_benchmark"))
    bench.dump_report()

Also, when adding print statements to bench_fn, it can be seen that bench_fn is never called with an argument other than 1, which I find unexpected.

System information

- Ubuntu 22.04.5 LTS in WSL2 on Windows 10
- mojo 2024.11.1705 (43b6e3df)
- magic 0.4.0 - (based on pixi 0.33.0)
@samufi samufi added bug Something isn't working mojo-repo Tag all issues with this label labels Nov 23, 2024
@samufi
Copy link
Author

samufi commented Nov 23, 2024

Because I could not find the source code for the benchmarking module (please let me know if I overlooked something), I made my own small implementation. Let me know if this could be of any help for comparing the actual implementation with one that works =).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

1 participant