create a benchmark tool to test api endpoints in csharp
main.cs
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;
classProgram{
staticasync Task Main() {
string apiUrl = "https://api.example.com/endpoint";
int numberOfRequests = 1000;
var httpClient = new HttpClient();
var stopwatch = new Stopwatch();
stopwatch.Start();
for (int i = 0; i < numberOfRequests; i++)
{
HttpResponseMessage response = await httpClient.GetAsync(apiUrl);
if (response.IsSuccessStatusCode)
{
// handle success if needed }
else {
// handle failure if needed }
}
stopwatch.Stop();
Console.WriteLine($"Total time taken for {numberOfRequests} requests: {stopwatch.Elapsed.TotalMilliseconds} ms");
}
}