1def bm_run(N, M):
2    try:
3        from utime import ticks_us, ticks_diff
4    except ImportError:
5        import time
6
7        ticks_us = lambda: int(time.perf_counter() * 1000000)
8        ticks_diff = lambda a, b: a - b
9
10    # Pick sensible parameters given N, M
11    cur_nm = (0, 0)
12    param = None
13    for nm, p in bm_params.items():
14        if 10 * nm[0] <= 12 * N and nm[1] <= M and nm > cur_nm:
15            cur_nm = nm
16            param = p
17    if param is None:
18        print(-1, -1, "no matching params")
19        return
20
21    # Run and time benchmark
22    run, result = bm_setup(param)
23    t0 = ticks_us()
24    run()
25    t1 = ticks_us()
26    norm, out = result()
27    print(ticks_diff(t1, t0), norm, out)
28