Click here to Skip to main content
13,254,366 members (57,806 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

9.4K views
Posted 20 Oct 2016

Restsharp Vs HttpClient Performance Benchmark

, 20 Oct 2016
Rate this:
Please Sign up or sign in to vote.
Restsharp Vs HttpClient Performance Benchmark

I am always a big fan of Restsharp, and have been using it for long time now. Especially recently as most of the projects I am working on involve Rest APIs.

The implementation is straight forward to make a call to an API and it supports Async calls as well.

Couple of days ago, I found myself calling a Rest API with the normal HttpClient and it crossed my mind about making a small comparison regarding the performance for both of them.

The test is simple as I have a Self host Web API (Owin) that includes one Get method[test] which returns a number from a static variable, this number increases by one every time a call is made to the API method.

public static int x = -1;
[Route("test")]
[HttpGet]
public IHttpActionResult Get()
{
x = x + 1;
return Ok(x);
}

API will be called from another console application within the same solution for both of the clients (Restsharp, HttpClient) asynchronously for number of times decided in the beginning of the console, the different time will be calculated by stopwatch object and print the result on the screen. Remember there is an initial request to the API in order to remove the delays occurred when you call the API for the first time.

Where is the Test !!

Ok, let's start the test with only 10 requests for each client and see the result.

Screenshot (31).png

As you see, restsharp took a bit longer but I thought that’s not a big difference as it is in milliseconds. At the end of the result, you will see that each time the API responses, the value getting stored in a list and when the test completes, the last item will be displayed in order to make sure that the result is correct. Let's make the test bigger by 500 requests.

Screenshot (28).png

Seems the gap is getting bigger now !! Double the time is something big when it comes to performance. What about we make the final round for 5000 requests!

Screenshot (30)

Again, the last round has proven that Restsharp is almost taking double the time. Well to be honest, I was expecting a slight difference in the performance as most the libraries built over the native classes usually takes more time than the original ones for the price of functionalities and features they offer but double the time is something that should be a concern.

Please note that both of the tests are done on 1 PC without any involvement of network factor as the API running from the same machine which runs the Test console APP to guarantee that network factor is not involved in the comparison between the calls for both of the clients. Also, all the calls were done asynchronously.

Conclusion

To be honest, I am still confused. I would love to do more tests whenever I get more time on both of the clients and if you have any ideas which would change the result, please let me know in the comments and I will take it into consideration in my next test.

You can find the complete solution in this link.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Amgad Fahmi
Software Developer (Senior)
United Arab Emirates United Arab Emirates
Genius is one percent inspiration and ninety-nine percent perspiration.

You may also be interested in...

Comments and Discussions

 
QuestionPossibly this is the reason? Pin
Member 1158520023-Oct-17 3:39
memberMember 1158520023-Oct-17 3:39 
QuestionThis test is probably seriously flawed somewhere Pin
tyzh10-Jun-17 6:04
membertyzh10-Jun-17 6:04 
SuggestionTests Pin
Graeme_Grant20-Oct-16 17:10
professionalGraeme_Grant20-Oct-16 17:10 
GeneralRe: Tests Pin
Amgad Fahmi20-Oct-16 22:05
memberAmgad Fahmi20-Oct-16 22:05 
GeneralRe: Tests Pin
Graeme_Grant21-Oct-16 14:19
professionalGraeme_Grant21-Oct-16 14:19 
GeneralRe: Tests Pin
Amgad Fahmi22-Oct-16 1:31
memberAmgad Fahmi22-Oct-16 1:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 20 Oct 2016
Article Copyright 2016 by Amgad Fahmi
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid