Restsharp Vs HttpClient performance benchmark


Am always a big fan of Restsharp , been using it for long time now. Specially recently as most of the projects am working on involves Rest APIs.
The implementation is straight forward to make a call to an API and it supports Async calls as well.

Couple of days back found my self 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) includes one Get method[test] which return a number from a static variable, this number increasing by one every time a call 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 lets 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 its 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. Lets 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 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 should be a concern.
Please not that both of the test are done on 1 PC without any involvement of network factor as the API running form 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. asynchronous


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

You can find the complete solution in the below link.



5 thoughts on “Restsharp Vs HttpClient performance benchmark

  1. I appreciate your time taken on testing both.
    It’s very basic, though.
    RestSharp bottleneck is it’s default json serializer/deserializer.
    You will also get different results depending on the instatiation strategy for the RestClient class (new for each request or reuse?).


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s