Skip to content

Commit f4f3b35

Browse files
author
Yash
committed
Writing ElapsedTime in the Console Output.
1 parent 61d5de2 commit f4f3b35

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

LinkCrawler/LinkCrawler/LinkCrawler.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@ public void SendRequest(string crawlUrl, string referrerUrl = "")
4242
{
4343
var requestModel = new RequestModel(crawlUrl, referrerUrl, BaseUrl);
4444
var restClient = new RestClient(new Uri(crawlUrl)) { FollowRedirects = false };
45-
46-
restClient.ExecuteAsync(RestRequest, response =>
45+
requestModel.StopWatch.Start();
46+
var x = restClient.ExecuteAsync(RestRequest, response =>
4747
{
4848
if (response == null)
4949
return;
50-
51-
var responseModel = new ResponseModel(response, requestModel, _settings);
50+
requestModel.StopWatch.Stop();
51+
var elapsedTimeSpan = requestModel.StopWatch.Elapsed;
52+
var responseModel = new ResponseModel(response, requestModel, _settings)
53+
{
54+
ElapsedTimeSpan = elapsedTimeSpan
55+
};
5256
ProcessResponse(responseModel);
5357
});
5458
}

LinkCrawler/LinkCrawler/Models/RequestModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using RestSharp;
1+
using System.Diagnostics;
2+
using RestSharp;
23

34
namespace LinkCrawler.Models
45
{
@@ -8,13 +9,15 @@ public class RequestModel
89
public string ReferrerUrl;
910
public bool IsInternalUrl { get; set; }
1011
public RestClient Client;
12+
public Stopwatch StopWatch;
1113

1214
public RequestModel(string url, string referrerUrl, string baseUrl)
1315
{
1416
Url = url;
1517
IsInternalUrl = url.StartsWith(baseUrl);
1618
ReferrerUrl = referrerUrl;
1719
Client = new RestClient(Url);
20+
StopWatch = new Stopwatch();
1821
}
1922
}
2023
}

LinkCrawler/LinkCrawler/Models/ResponseModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class ResponseModel : IResponseModel
1616
public int StatusCodeNumber { get { return (int)StatusCode; } }
1717
public bool IsSuccess { get; }
1818
public bool ShouldCrawl { get; }
19+
public TimeSpan ElapsedTimeSpan { get; set; }
1920

2021
public ResponseModel(IRestResponse restResponse, RequestModel requestModel, ISettings settings)
2122
{
@@ -34,7 +35,7 @@ public override string ToString()
3435
if (!IsSuccess)
3536
return string.Format("{0}\t{1}\t{2}{3}\tReferer:\t{4}", StatusCodeNumber, StatusCode, RequestedUrl, Environment.NewLine, ReferrerUrl);
3637

37-
return string.Format("{0}\t{1}\t{2}", StatusCodeNumber, StatusCode, RequestedUrl);
38+
return string.Format("{0}\t{1}\t{2}\t{3}", StatusCodeNumber, StatusCode, RequestedUrl, ElapsedTimeSpan.ToString());
3839
}
3940
}
4041
}

0 commit comments

Comments
 (0)