C
C#11mo ago
goated

I need some help with attribute

Welp I don't know much about attribute and GPT keeps sending me s*** code Anyone can give me an example on how to do this: When we call a function with a attribute [timerTest] It will print out how long does the function runs
11 Replies
Denis
Denis11mo ago
Do you want to do code benchmarks? If so, use BenchmarkDotNet Otherwise, the magic is not in the attribute. It is only used to mark parts of your code. Implementing what you want might be possible via partial methods and source generators, I guess. But I haven't researched that yet
goated
goatedOP11mo ago
Oh
Jimmacle
Jimmacle11mo ago
this sounds like it's potentially a job for interceptors but those are experimental
Denis
Denis11mo ago
True
Jimmacle
Jimmacle11mo ago
basically this is a lot more complicated to do than you think it is it would be easier to just wrap the call in a stopwatch or use an actual benchmarking framework like $bdn
MODiX
MODiX11mo ago
Try BenchmarkDotNet if you want a sophisticated library for benchmarking https://github.com/dotnet/BenchmarkDotNet
Denis
Denis11mo ago
But again, if you want to bench your code, use a well tested library Like the one mentioned above
goated
goatedOP11mo ago
Thanks this seems like what I'm looking for
Jimmacle
Jimmacle11mo ago
it's definitely what you want if you want accurate measurements, calling a method once won't get you a realistic execution time because of the JIT and progressive optimization
Denis
Denis11mo ago
$close
MODiX
MODiX11mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server