Here’s a brief README.md for your project:
This project demonstrates how to measure the performance of API endpoints in a .NET 8 Web API using two different approaches:
- Manual measurement using
Stopwatch. - Automated method measurement using the MethodTimer.Fody library.
-
GET /WeatherForecast/simple: Measures the performance manually usingStopwatchand logs the elapsed time to the console. -
GET /WeatherForecast/fody: Uses the MethodTimer.Fody library to automatically log the performance time to the debug window.
Both endpoints simulate a long-running operation and return a weather forecast for the next 5 days.
- Stopwatch: Manually starts and stops to measure elapsed time.
- MethodTimer.Fody: Automatically tracks and logs the execution time of any decorated method (marked with
[Time]attribute).
- .NET 8 SDK
- Visual Studio or any preferred C# IDE
- Clone or download the project.
- Restore the NuGet packages:
dotnet restore
- Run the application:
dotnet run
Once the project is running, Swagger will be available at:
http://localhost:<port>/swagger
This UI allows you to test the API endpoints easily.
-
For
/WeatherForecast/simple:- Call the endpoint via Swagger or directly using a tool like Postman.
- Observe the performance logs in the console window. The elapsed time in milliseconds will be printed using
Stopwatch.
-
For
/WeatherForecast/fody:- Call the endpoint via Swagger or Postman.
- Check the debug window (Output window in Visual Studio) for the performance logs, which are automatically logged by the MethodTimer.Fody library.