Skip to content

Commit

Permalink
perf: benchmark
Browse files Browse the repository at this point in the history
perf: benchmark
  • Loading branch information
egbakou authored Dec 11, 2022
2 parents 2b891aa + 472895b commit 76b85b0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 41 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Documentation of the previous versions can be found [here](https://github.com/eg
| Start of the week || ✔️ |
| Mobile phone prefix information || ✔️ |

## Benchmark

![](art/benchmark.png)

## Note

Add `namespace` `RESTCountries.NET.Services` and call `RestCountriesService` class to access all methods.
Expand Down
Binary file added art/benchmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 2 additions & 14 deletions tests/RESTCountries.NET.Benchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Validators;
using BenchmarkDotNet.Running;
using RESTCountries.NET.Benchmark;

// CountryData.Standard is not optimized during build,
// So to avoid benchmark errors, we need to disable the OptimizationValidator
var config = new ManualConfig()
.WithOptions(ConfigOptions.DisableOptimizationsValidator)
.AddValidator(JitOptimizationsValidator.DontFailOnError)
.AddLogger(ConsoleLogger.Default)
.AddColumnProvider(DefaultColumnProviders.Instance);

BenchmarkRunner.Run<RestCountriesServiceBenchmark>(config);
BenchmarkRunner.Run<RestCountriesServiceBenchmark>();
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.2" />
<PackageReference Include="CountryData.Standard" Version="1.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
28 changes: 2 additions & 26 deletions tests/RESTCountries.NET.Benchmark/RestCountriesServiceBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,14 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using CountryData.Standard;
using RESTCountries.NET.Services;
using Country = RESTCountries.NET.Models.Country;
using CountryDataCountry = CountryData.Standard.Country;
using RESTCountries.NET.Models;

namespace RESTCountries.NET.Benchmark;

[MemoryDiagnoser]
[MediumRunJob]
[Config(typeof(Config))]
public class RestCountriesServiceBenchmark
{
private class Config : ManualConfig
{
public Config()
{
AddJob(Job.MediumRun);
AddColumn(new TagColumn("Nuget", name =>
name.StartsWith("GetAll") ? "RESTCountries.NET 3.0.0" : "CountryData.Standard 1.3.0"));
}
}

[Benchmark]
[Arguments("RESTCountries.NET")]
public List<Country> GetAllCountries() => RestCountriesService.GetAllCountries().ToList();

[Benchmark]
[Arguments("CountryData.Standard")]
public List<CountryDataCountry> GetCountryData()
{
var helper = new CountryHelper();
return helper.GetCountryData().ToList();
}
public List<Country> GetAllCountries() => RestCountriesService.GetAllCountries().ToList();
}

0 comments on commit 76b85b0

Please sign in to comment.