Click here to Skip to main content
15,307,242 members
Articles / All Topics
Technical Blog
Posted 20 Oct 2016

Tagged as


2 bookmarked

Restsharp Vs HttpClient Performance Benchmark

Rate me:
Please Sign up or sign in to vote.
4.31/5 (7 votes)
20 Oct 2016CPOL3 min read
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;
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.


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.

Image 4 Image 5


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


About the Author

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

Comments and Discussions

QuestionPossibly this is the reason? Pin
Member 1158520023-Oct-17 2:39
MemberMember 1158520023-Oct-17 2:39 
QuestionThis test is probably seriously flawed somewhere Pin
tyzh10-Jun-17 5:04
Membertyzh10-Jun-17 5:04 
SuggestionTests Pin
Graeme_Grant20-Oct-16 16:10
professionalGraeme_Grant20-Oct-16 16:10 
GeneralRe: Tests Pin
Amgad Fahmi20-Oct-16 21:05
MemberAmgad Fahmi20-Oct-16 21:05 
GeneralRe: Tests Pin
Graeme_Grant21-Oct-16 13:19
professionalGraeme_Grant21-Oct-16 13:19 
GeneralRe: Tests Pin
Amgad Fahmi22-Oct-16 0:31
MemberAmgad Fahmi22-Oct-16 0: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.