Skip to content

Commit

Permalink
Merge pull request #24 from martincostello/Update-Benchmarks
Browse files Browse the repository at this point in the history
Update benchmarks
  • Loading branch information
martincostello authored Mar 11, 2018
2 parents 2a014ac + cfcbcd9 commit 3e5610d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 33 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,24 @@ Further examples of using the library can be found by following the links below:

### Benchmarks

Generated with the [Benchmarks project](https://github.com/justeat/httpclient-interception/blob/master/tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs "JustEat.HttpClientInterception benchmark code") using [BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet "BenchmarkDotNet on GitHub.com") using commit [a442f1d](https://github.com/justeat/httpclient-interception/commit/a442f1d72701bedd5920be23561c1e12a05fb43f "Benchmark commit") on 23/09/2017.
Generated with the [Benchmarks project](https://github.com/justeat/httpclient-interception/blob/master/tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs "JustEat.HttpClientInterception benchmark code") using [BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet "BenchmarkDotNet on GitHub.com") using commit [c09c38b](https://github.com/justeat/httpclient-interception/commit/c09c38bad3ed5db6cfffdbaebeac33c2d286764f "Benchmark commit") on 11/03/2018.

``` ini
BenchmarkDotNet=v0.10.9, OS=Windows 10 Redstone 2 (10.0.15063)
Processor=Intel Core i7-6500U CPU 2.50GHz (Skylake), ProcessorCount=4
Frequency=2531249 Hz, Resolution=395.0619 ns, Timer=TSC
.NET Core SDK=2.0.0
[Host] : .NET Core 2.0.0 (Framework 4.6.00001.0), 64bit RyuJIT
DefaultJob : .NET Core 2.0.0 (Framework 4.6.00001.0), 64bit RyuJIT
BenchmarkDotNet=v0.10.12, OS=Windows 10 Redstone 3 [1709, Fall Creators Update] (10.0.16299.248)
Intel Core i7-6700HQ CPU 2.60GHz (Skylake), 1 CPU, 8 logical cores and 4 physical cores
Frequency=2531248 Hz, Resolution=395.0620 ns, Timer=TSC
.NET Core SDK=2.1.4
[Host] : .NET Core 2.0.5 (Framework 4.6.26020.03), 64bit RyuJIT
DefaultJob : .NET Core 2.0.5 (Framework 4.6.26020.03), 64bit RyuJIT
```

| Method | Mean | Error | StdDev |
|---------- |----------:|----------:|----------:|
| [`GetBytes`](https://github.com/justeat/httpclient-interception/blob/a442f1d72701bedd5920be23561c1e12a05fb43f/tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs#L61-L65 "Benchmark using a byte array") | 3.604 μs | 0.0639 μs | 0.0567 μs |
| [`GetHtml`](https://github.com/justeat/httpclient-interception/blob/a442f1d72701bedd5920be23561c1e12a05fb43f/tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs#L67-L71 "Benchmark using HTML") | 4.674 μs | 0.0881 μs | 0.0781 μs |
| [`GetJson`](https://github.com/justeat/httpclient-interception/blob/a442f1d72701bedd5920be23561c1e12a05fb43f/tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs#L73-L78 "Benchmark using JSON") | 12.295 μs | 0.2015 μs | 0.1683 μs |
| [`GetStream`](https://github.com/justeat/httpclient-interception/blob/a442f1d72701bedd5920be23561c1e12a05fb43f/tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs#L80-L86 "Benchmark using a stream") | 99.040 μs | 1.9611 μs | 3.0531 μs |
| [`Refit`](https://github.com/justeat/httpclient-interception/blob/a442f1d72701bedd5920be23561c1e12a05fb43f/tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs#L88-L92 "Benchmark using Refit") | 33.651 μs | 0.5165 μs | 0.4831 μs |
| [`GetBytes`](https://github.com/justeat/httpclient-interception/blob/c09c38bad3ed5db6cfffdbaebeac33c2d286764f/tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs#L73-L77 "Benchmark using a byte array") | 8.310 μs | 0.0916 μs | 0.0857 μs |
| [`GetHtml`](https://github.com/justeat/httpclient-interception/blob/c09c38bad3ed5db6cfffdbaebeac33c2d286764f/tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs#L79-L83 "Benchmark using HTML") | 8.476 μs | 0.0462 μs | 0.0361 μs |
| [`GetJson`](https://github.com/justeat/httpclient-interception/blob/c09c38bad3ed5db6cfffdbaebeac33c2d286764f/tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs#L85-L90 "Benchmark using JSON") | 17.519 μs | 0.2440 μs | 0.2282 μs |
| [`GetStream`](https://github.com/justeat/httpclient-interception/blob/c09c38bad3ed5db6cfffdbaebeac33c2d286764f/tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs#L92-L98 "Benchmark using a stream") | 72.442 μs | 0.9177 μs | 0.8135 μs |
| [`Refit`](https://github.com/justeat/httpclient-interception/blob/c09c38bad3ed5db6cfffdbaebeac33c2d286764f/tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs#L100-L104 "Benchmark using Refit") | 46.388 μs | 0.4742 μs | 0.4436 μs |

## Feedback

Expand Down
54 changes: 33 additions & 21 deletions tests/HttpClientInterception.Benchmarks/InterceptionBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,53 @@ public class InterceptionBenchmarks

public InterceptionBenchmarks()
{
var builderForBytes = new HttpRequestInterceptionBuilder()
.ForHttps()
.ForHost("files.domain.com")
.ForPath("setup.exe")
.WithMediaType("application/octet-stream")
.WithContent(() => new byte[] { 0, 1, 2, 3, 4 });
_options = new HttpClientInterceptorOptions()
{
ThrowOnMissingRegistration = true,
};

var builderForHtml = new HttpRequestInterceptionBuilder()
var builder = new HttpRequestInterceptionBuilder();

builder
.Requests()
.ForHttp()
.ForHost("www.google.co.uk")
.ForPath("search")
.ForQuery("q=Just+Eat")
.Responds()
.WithMediaType("text/html")
.WithContent(@"<!DOCTYPE html><html dir=""ltr"" lang=""en""><head><title>Just Eat</title></head></html>");
.WithContent(@"<!DOCTYPE html><html dir=""ltr"" lang=""en""><head><title>Just Eat</title></head></html>")
.RegisterWith(_options);

var builderForJson = new HttpRequestInterceptionBuilder()
builder
.Requests()
.ForHttps()
.ForHost("api.github.com")
.ForPath("orgs/justeat")
.WithMediaType("application/json")
.WithJsonContent(new { id = 1516790, login = "justeat", url = "https://api.github.com/orgs/justeat" });
.ForPort(443)
.ForHost("files.domain.com")
.ForPath("setup.exe")
.ForQuery(string.Empty)
.Responds()
.WithMediaType("application/octet-stream")
.WithContent(() => new byte[] { 0, 1, 2, 3, 4 })
.RegisterWith(_options);

var builderForStream = new HttpRequestInterceptionBuilder()
builder
.Requests()
.ForHttps()
.ForHost("api.github.com")
.ForPath("orgs/justeat")
.ForQuery("page=1")
.ForQuery(string.Empty)
.Responds()
.WithMediaType("application/json")
.WithContentStream(() => File.OpenRead("organization.json"));
.WithJsonContent(new { id = 1516790, login = "justeat", url = "https://api.github.com/orgs/justeat" })
.RegisterWith(_options);

_options = new HttpClientInterceptorOptions()
.Register(builderForBytes)
.Register(builderForHtml)
.Register(builderForJson)
.Register(builderForStream);
builder
.Requests()
.ForQuery("page=1")
.Responds()
.WithContentStream(() => File.OpenRead("organization.json"))
.RegisterWith(_options);

_client = _options.CreateHttpClient();
_service = RestService.For<IGitHub>(_options.CreateHttpClient("https://api.github.com"));
Expand Down

0 comments on commit 3e5610d

Please sign in to comment.