M
Modular5mo ago
tkeitt

Benchmarking code that raises

I am trying to use benchmark to time numpy code. However, numpy raises and it appears that benchmark.run cannot handle a function that raises. I am not a python programmer, so I am not familiar with the exception syntax. Is there a way to wrap numpy code such that the surrounding function does not raise?
2 Replies
Jack Clayton
Jack Clayton5mo ago
Yeah you can wrap it in try/except:
from python import Python
from benchmark import run


fn main():
fn bench():
try:
Python.evaluate("x**2")
except:
pass

var res = run[bench]().mean("ns")
print(res)
from python import Python
from benchmark import run


fn main():
fn bench():
try:
Python.evaluate("x**2")
except:
pass

var res = run[bench]().mean("ns")
print(res)
tkeitt
tkeittOP5mo ago
I tried that and it did not work. I'll give it another go.
Want results from more Discord servers?
Add your server