C
C#5mo 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
Denis5mo 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
goated5mo ago
Oh
Jimmacle
Jimmacle5mo ago
this sounds like it's potentially a job for interceptors but those are experimental
Denis
Denis5mo ago
True
Jimmacle
Jimmacle5mo 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
MODiX5mo ago
Try BenchmarkDotNet if you want a sophisticated library for benchmarking https://github.com/dotnet/BenchmarkDotNet
Denis
Denis5mo ago
But again, if you want to bench your code, use a well tested library Like the one mentioned above
goated
goated5mo ago
Thanks this seems like what I'm looking for
Jimmacle
Jimmacle5mo 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
Denis5mo ago
$close
MODiX
MODiX5mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server
More Posts