Skip to content

Commit

Permalink
test: executar testes de benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
hd1fernando committed Nov 14, 2024
1 parent d3df9f1 commit 701d069
Show file tree
Hide file tree
Showing 8 changed files with 217 additions and 78 deletions.
54 changes: 27 additions & 27 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
name: .NET

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'
- name: Restore dependencies
run: dotnet restore src/Jabuticaba/
- name: Build
run: dotnet build --no-restore src/Jabuticaba/
- name: Test
run: dotnet test --no-build --verbosity normal test/JabuticabaTests/
- name: Publish Nuget Package
run: dotnet nuget push **/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
name: .NET

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'
- name: Restore dependencies
run: dotnet restore src/Jabuticaba/
- name: Build
run: dotnet build --no-restore src/Jabuticaba/
- name: Test
run: dotnet test --no-build --verbosity normal test/JabuticabaTests/
- name: Publish Nuget Package
run: dotnet nuget push **/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
42 changes: 2 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,8 @@ Console.WriteLine(cnpj.EValido);
```

## Benchmark
``` bash
// * Legends *
BenchmarkDotNet=v0.12.1, OS=ubuntu 20.04
AMD Ryzen 5 3400G with Radeon Vega Graphics, 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=5.0.101
[Host] : .NET Core 5.0.1 (CoreCLR 5.0.120.57516, CoreFX 5.0.120.57516), X64 RyuJIT
DefaultJob : .NET Core 5.0.1 (CoreCLR 5.0.120.57516, CoreFX 5.0.120.57516), X64 RyuJIT


| Method | Mean | Error | StdDev | Median | Rank | Gen 0 | Gen 1 | Gen 2 | Allocated |
|------------------------------ |----------:|---------:|----------:|----------:|-----:|-------:|------:|------:|----------:|
| ObterCpf | 55.70 ns | 1.092 ns | 1.022 ns | 55.60 ns | 1 | - | - | - | - |
| CpfApenasDigitosRepetidos | 62.27 ns | 1.254 ns | 1.444 ns | 62.13 ns | 2 | - | - | - | - |
| CpfPrimeiroDigitoInvalido | 99.88 ns | 4.280 ns | 12.620 ns | 94.13 ns | 3 | 0.0421 | - | - | 88 B |
| CpfSegundoDigitoInvalido | 107.18 ns | 2.146 ns | 3.146 ns | 106.61 ns | 4 | 0.0421 | - | - | 88 B |
| CpfTamanhoMenorDoQue11Digitos | 240.83 ns | 3.868 ns | 4.299 ns | 240.59 ns | 5 | 0.0725 | - | - | 152 B |
| CpfTamanhoMaiorDoQue11Digitos | 255.29 ns | 4.031 ns | 3.573 ns | 255.30 ns | 6 | 0.0763 | - | - | 160 B |
| CpfContendoValorNaoNumerico | 427.66 ns | 8.255 ns | 8.108 ns | 428.53 ns | 7 | 0.1488 | - | - | 312 B |

| Method | Mean | Error | StdDev | Rank | Gen 0 | Gen 1 | Gen 2 | Allocated |
|--------------------------- |----------:|---------:|---------:|-----:|-------:|------:|------:|----------:|
| CnpjSemMascara | 67.85 ns | 0.416 ns | 0.389 ns | 1 | - | - | - | - |
| ObterCnpj | 75.87 ns | 0.758 ns | 0.672 ns | 2 | - | - | - | - |
| CnpjSegundoDigitoInvalido | 101.82 ns | 2.066 ns | 3.337 ns | 3 | 0.0459 | - | - | 96 B |
| CnpjPrimeiroDigitoInvalido | 112.16 ns | 2.267 ns | 2.699 ns | 4 | 0.0459 | - | - | 96 B |
| CnpjMaiorDoQue14Digitos | 259.65 ns | 4.840 ns | 4.753 ns | 5 | 0.0763 | - | - | 160 B |
| CnpjMenorDoQue14Digitos | 265.31 ns | 5.343 ns | 7.132 ns | 5 | 0.0763 | - | - | 160 B |
| CnpjValorNaoNumerico | 436.29 ns | 6.250 ns | 5.846 ns | 6 | 0.1526 | - | - | 320 B |

// * Legends *
Mean : Arithmetic mean of all measurements
Error : Half of 99.9% confidence interval
StdDev : Standard deviation of all measurements
Ratio : Mean of the ratio distribution ([Current]/[Baseline])
Gen 0 : GC Generation 0 collects per 1000 operations
Gen 1 : GC Generation 1 collects per 1000 operations
Gen 2 : GC Generation 2 collects per 1000 operations
Allocated : Allocated memory per single operation (managed only, inclusive, 1KB = 1024B)
1 ns : 1 Nanosecond (0.000000001 sec)
```
Clique [aqui](https://github.com/hd1fernando/Jabuticaba/blob/main/benchmark/DiagnoseResult.md) para ver o último resultado do teste de benchmark

## Detalhes do projeto
* [GitFlow](https://www.atlassian.com/br/git/tutorials/comparing-workflows/gitflow-workflow) para fluxo de trabalho com Git.

Expand Down
165 changes: 165 additions & 0 deletions benchmark/DiagnoseResult.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
``` bash

// * Detailed results *
CpfBenchmarkDiagnoser.CpfApenasDigitosRepetidos: DefaultJob
Runtime = .NET 6.0.36 (6.0.3624.51421), X64 RyuJIT; GC = Concurrent Workstation
Mean = 59.700 ns, StdErr = 0.361 ns (0.60%), N = 85, StdDev = 3.328 ns
Min = 54.100 ns, Q1 = 57.141 ns, Median = 59.039 ns, Q3 = 61.630 ns, Max = 68.872 ns
IQR = 4.489 ns, LowerFence = 50.407 ns, UpperFence = 68.364 ns
ConfidenceInterval = [58.469 ns; 60.931 ns] (CI 99.9%), Margin = 1.231 ns (2.06% of Mean)
Skewness = 0.8, Kurtosis = 3.24, MValue = 2
-------------------- Histogram --------------------
[53.106 ns ; 55.306 ns) | @@@@
[55.306 ns ; 57.642 ns) | @@@@@@@@@@@@@@@@@@@@
[57.642 ns ; 59.629 ns) | @@@@@@@@@@@@@@@@@@@@@@@@@@
[59.629 ns ; 61.907 ns) | @@@@@@@@@@@@@@@@@@
[61.907 ns ; 64.438 ns) | @@@@@@@
[64.438 ns ; 66.424 ns) | @@@@@@
[66.424 ns ; 69.188 ns) | @@@@
---------------------------------------------------

CpfBenchmarkDiagnoser.CpfPrimeiroDigitoInvalido: DefaultJob
Runtime = .NET 6.0.36 (6.0.3624.51421), X64 RyuJIT; GC = Concurrent Workstation
Mean = 76.688 ns, StdErr = 0.410 ns (0.53%), N = 22, StdDev = 1.924 ns
Min = 73.621 ns, Q1 = 75.018 ns, Median = 76.659 ns, Q3 = 78.250 ns, Max = 80.154 ns
IQR = 3.232 ns, LowerFence = 70.170 ns, UpperFence = 83.098 ns
ConfidenceInterval = [75.121 ns; 78.255 ns] (CI 99.9%), Margin = 1.567 ns (2.04% of Mean)
Skewness = 0.04, Kurtosis = 1.74, MValue = 2
-------------------- Histogram --------------------
[72.720 ns ; 76.044 ns) | @@@@@@@@
[76.044 ns ; 78.400 ns) | @@@@@@@@
[78.400 ns ; 80.202 ns) | @@@@@@
---------------------------------------------------

CpfBenchmarkDiagnoser.ObterCpf: DefaultJob
Runtime = .NET 6.0.36 (6.0.3624.51421), X64 RyuJIT; GC = Concurrent Workstation
Mean = 77.373 ns, StdErr = 1.021 ns (1.32%), N = 99, StdDev = 10.156 ns
Min = 65.659 ns, Q1 = 69.935 ns, Median = 73.278 ns, Q3 = 82.934 ns, Max = 102.749 ns
IQR = 12.999 ns, LowerFence = 50.437 ns, UpperFence = 102.432 ns
ConfidenceInterval = [73.910 ns; 80.836 ns] (CI 99.9%), Margin = 3.463 ns (4.48% of Mean)
Skewness = 0.99, Kurtosis = 2.79, MValue = 2.33
-------------------- Histogram --------------------
[62.777 ns ; 66.320 ns) | @
[66.320 ns ; 72.083 ns) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
[72.083 ns ; 78.163 ns) | @@@@@@@@@@@@@@@@@
[78.163 ns ; 83.926 ns) | @@@@@@@@@@@@@@@
[83.926 ns ; 90.036 ns) | @@@@@@@
[90.036 ns ; 93.097 ns) | @
[93.097 ns ; 98.860 ns) | @@@@@@@@@
[98.860 ns ; 105.631 ns) | @@@@@
---------------------------------------------------

CpfBenchmarkDiagnoser.CpfSegundoDigitoInvalido: DefaultJob
Runtime = .NET 6.0.36 (6.0.3624.51421), X64 RyuJIT; GC = Concurrent Workstation
Mean = 85.206 ns, StdErr = 0.686 ns (0.80%), N = 97, StdDev = 6.755 ns
Min = 75.588 ns, Q1 = 79.502 ns, Median = 83.525 ns, Q3 = 90.310 ns, Max = 104.780 ns
IQR = 10.808 ns, LowerFence = 63.290 ns, UpperFence = 106.521 ns
ConfidenceInterval = [82.878 ns; 87.534 ns] (CI 99.9%), Margin = 2.328 ns (2.73% of Mean)
Skewness = 0.79, Kurtosis = 2.85, MValue = 2.5
-------------------- Histogram --------------------
[ 73.659 ns ; 77.154 ns) | @@
[ 77.154 ns ; 81.014 ns) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
[ 81.014 ns ; 85.258 ns) | @@@@@@@@@@@@@@@@@@@
[ 85.258 ns ; 88.297 ns) | @@@@@@@@
[ 88.297 ns ; 92.157 ns) | @@@@@@@@@@@@@@@@@
[ 92.157 ns ; 96.316 ns) | @@@@@@@@@@
[ 96.316 ns ; 101.737 ns) | @@@
[101.737 ns ; 106.709 ns) | @@
---------------------------------------------------

CpfBenchmarkDiagnoser.CpfTamanhoMaiorDoQue11Digitos: DefaultJob
Runtime = .NET 6.0.36 (6.0.3624.51421), X64 RyuJIT; GC = Concurrent Workstation
Mean = 99.843 ns, StdErr = 0.594 ns (0.60%), N = 79, StdDev = 5.282 ns
Min = 91.066 ns, Q1 = 96.432 ns, Median = 98.102 ns, Q3 = 102.914 ns, Max = 113.190 ns
IQR = 6.482 ns, LowerFence = 86.708 ns, UpperFence = 112.638 ns
ConfidenceInterval = [97.811 ns; 101.876 ns] (CI 99.9%), Margin = 2.032 ns (2.04% of Mean)
Skewness = 0.85, Kurtosis = 2.88, MValue = 2.13
-------------------- Histogram --------------------
[ 89.450 ns ; 91.813 ns) | @
[ 91.813 ns ; 95.045 ns) | @@@@@@@@@@@@
[ 95.045 ns ; 98.936 ns) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
[ 98.936 ns ; 102.617 ns) | @@@@@@@@@@@@@@@@
[102.617 ns ; 106.390 ns) | @@@@@@@@
[106.390 ns ; 110.100 ns) | @@@@@
[110.100 ns ; 113.331 ns) | @@@@@@@
---------------------------------------------------

CpfBenchmarkDiagnoser.CpfTamanhoMenorDoQue11Digitos: DefaultJob
Runtime = .NET 6.0.36 (6.0.3624.51421), X64 RyuJIT; GC = Concurrent Workstation
Mean = 107.512 ns, StdErr = 1.523 ns (1.42%), N = 95, StdDev = 14.844 ns
Min = 89.616 ns, Q1 = 96.603 ns, Median = 103.258 ns, Q3 = 115.640 ns, Max = 152.763 ns
IQR = 19.037 ns, LowerFence = 68.048 ns, UpperFence = 144.196 ns
ConfidenceInterval = [102.339 ns; 112.686 ns] (CI 99.9%), Margin = 5.173 ns (4.81% of Mean)
Skewness = 1.16, Kurtosis = 3.62, MValue = 2.24
-------------------- Histogram --------------------
[ 85.346 ns ; 91.623 ns) | @@@@
[ 91.623 ns ; 100.162 ns) | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
[100.162 ns ; 108.684 ns) | @@@@@@@@@@@@@@@@@@@@@@
[108.684 ns ; 116.615 ns) | @@@@@@@@
[116.615 ns ; 125.154 ns) | @@@@@@@@@@@@@
[125.154 ns ; 129.063 ns) | @
[129.063 ns ; 137.602 ns) | @@@@@@
[137.602 ns ; 144.936 ns) |
[144.936 ns ; 153.476 ns) | @@@@
---------------------------------------------------

CpfBenchmarkDiagnoser.CpfContendoValorNaoNumerico: DefaultJob
Runtime = .NET 6.0.36 (6.0.3624.51421), X64 RyuJIT; GC = Concurrent Workstation
Mean = 111.993 ns, StdErr = 0.750 ns (0.67%), N = 94, StdDev = 7.272 ns
Min = 100.128 ns, Q1 = 106.017 ns, Median = 110.300 ns, Q3 = 116.772 ns, Max = 134.739 ns
IQR = 10.755 ns, LowerFence = 89.885 ns, UpperFence = 132.905 ns
ConfidenceInterval = [109.444 ns; 114.542 ns] (CI 99.9%), Margin = 2.549 ns (2.28% of Mean)
Skewness = 0.88, Kurtosis = 3.67, MValue = 2
-------------------- Histogram --------------------
[ 98.029 ns ; 101.619 ns) | @@
[101.619 ns ; 105.949 ns) | @@@@@@@@@@@@@@@@@@@
[105.949 ns ; 110.147 ns) | @@@@@@@@@@@@@@@@@@@@@@@@@
[110.147 ns ; 114.255 ns) | @@@@@@@@@@@@@@@@@@
[114.255 ns ; 116.563 ns) | @@@@@
[116.563 ns ; 120.762 ns) | @@@@@@@@@@@@@@@@@@
[120.762 ns ; 127.263 ns) | @@@@
[127.263 ns ; 131.612 ns) |
[131.612 ns ; 135.811 ns) | @@@
---------------------------------------------------

// * Summary *

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.22631
11th Gen Intel Core i5-1135G7 2.40GHz, 1 CPU, 8 logical and 4 physical cores
.NET SDK=8.0.404
[Host] : .NET 6.0.36 (6.0.3624.51421), X64 RyuJIT
DefaultJob : .NET 6.0.36 (6.0.3624.51421), X64 RyuJIT


| Method | Mean | Error | StdDev | Median | Rank | Gen 0 | Allocated |
|------------------------------ |----------:|---------:|----------:|----------:|-----:|-------:|----------:|
| CpfApenasDigitosRepetidos | 59.70 ns | 1.231 ns | 3.328 ns | 59.04 ns | 1 | - | - |
| CpfPrimeiroDigitoInvalido | 76.69 ns | 1.567 ns | 1.924 ns | 76.66 ns | 2 | 0.0210 | 88 B |
| ObterCpf | 77.37 ns | 3.463 ns | 10.156 ns | 73.28 ns | 2 | - | - |
| CpfSegundoDigitoInvalido | 85.21 ns | 2.328 ns | 6.755 ns | 83.53 ns | 3 | 0.0210 | 88 B |
| CpfTamanhoMaiorDoQue11Digitos | 99.84 ns | 2.032 ns | 5.282 ns | 98.10 ns | 4 | 0.0324 | 136 B |
| CpfTamanhoMenorDoQue11Digitos | 107.51 ns | 5.173 ns | 14.844 ns | 103.26 ns | 5 | 0.0305 | 128 B |
| CpfContendoValorNaoNumerico | 111.99 ns | 2.549 ns | 7.272 ns | 110.30 ns | 6 | 0.0573 | 240 B |

// * Hints *
Outliers
CpfBenchmarkDiagnoser.CpfApenasDigitosRepetidos: Default -> 8 outliers were removed (72.38 ns..80.31 ns)
CpfBenchmarkDiagnoser.CpfPrimeiroDigitoInvalido: Default -> 6 outliers were removed (90.14 ns..110.32 ns)
CpfBenchmarkDiagnoser.ObterCpf: Default -> 1 outlier was removed (103.84 ns)
CpfBenchmarkDiagnoser.CpfSegundoDigitoInvalido: Default -> 3 outliers were removed (116.12 ns..124.13 ns)
CpfBenchmarkDiagnoser.CpfTamanhoMaiorDoQue11Digitos: Default -> 6 outliers were removed (119.21 ns..134.32 ns)
CpfBenchmarkDiagnoser.CpfTamanhoMenorDoQue11Digitos: Default -> 5 outliers were removed (166.14 ns..207.73 ns)
CpfBenchmarkDiagnoser.CpfContendoValorNaoNumerico: Default -> 6 outliers were removed (140.07 ns..145.31 ns)

// * Legends *
Mean : Arithmetic mean of all measurements
Error : Half of 99.9% confidence interval
StdDev : Standard deviation of all measurements
Median : Value separating the higher half of all measurements (50th percentile)
Rank : Relative position of current benchmark mean among all benchmarks (Arabic style)
Gen 0 : GC Generation 0 collects per 1000 operations
Allocated : Allocated memory per single operation (managed only, inclusive, 1KB = 1024B)
1 ns : 1 Nanosecond (0.000000001 sec)

// * Diagnostic Output - MemoryDiagnoser *
```
8 changes: 8 additions & 0 deletions benchmark/Jabuticaba.Benchmark/CnpjBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ GC geração 2 - 0
GC geração 1 - 0
GC geração 0 - 0
12/26/2020 9:17:20 AM
Cnpj:
Quantidade de cnpjs 1000000
Tempo execução: 182ms
GC geração 2 - 0
GC geração 1 - 0
GC geração 0 - 0
14/11/2024 19:49:49
*/
public void Executar(ulong numeroTentativas)
{
Expand Down
8 changes: 8 additions & 0 deletions benchmark/Jabuticaba.Benchmark/CpfBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ GC geração 2 - 0
GC geração 1 - 0
GC geração 0 - 0
12/26/2020 7:49:36 AM
Cpf:
Quantidade de cpfs 1000000
Tempo execução: 94ms
GC geração 2 - 0
GC geração 1 - 0
GC geração 0 - 0
14/11/2024 19:49:49
*/
public void Executar(ulong numeroTentativas)
{
Expand Down
6 changes: 2 additions & 4 deletions benchmark/Jabuticaba.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ class Program
static void Main(string[] args)
{
#if RELEASE
// var summaryCpf = BenchmarkRunner.Run<CpfBenchmarkDiagnoser>();
// var summaryCnpj = BenchmarkRunner.Run<CnpjBenchmarkDiagnoser>();
var summaryCep = BenchmarkRunner.Run<CepBenchmarkDiagnoser>();
// var summarytelefone = BenchmarkRunner.Run<TelefoneBenchmarkDiagnoser>();
var summaryCpf = BenchmarkRunner.Run<CpfBenchmarkDiagnoser>();
var summaryCnpj = BenchmarkRunner.Run<CnpjBenchmarkDiagnoser>();
#endif

List<IBenchmarkLocal> benchmarks = new()
Expand Down
2 changes: 1 addition & 1 deletion executar-benchmark.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cd benchmark/Jabuticaba.Benchmark
dotnet build -c Release
cd bin/Release/net5.0
cd bin/Release/net6.0
dotnet Jabuticaba.Benchmark.dll
10 changes: 4 additions & 6 deletions src/Jabuticaba/Jabuticaba.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<PackageId>jabuticaba</PackageId>
<Version>1.0.0</Version>
<Version>2.0.0</Version>
<Authors>hd1Fernando</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Description>
Jabuticaba é uma biblioteca que fornece, em formato de tipos, valores utilizados no Brasil. Como CPF, CNPJ e etc.
Jabuticaba é uma biblioteca que fornece, em formato de tipos, valores utilizados no Brasil. Como CPF e CNPJ.

Seu principal objetivo que que o desenvolvedor não tenha necessidade de ficar recriando tipos quando for preciso lidar com um novo tipo em sua aplicação além de buscar por alta performance.
</Description>
<PackageProjectUrl></PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Copyright>2022</Copyright>
<RepositoryUrl>https://github.com/hd1fernando/Jabuticaba</RepositoryUrl>
<PackageTags>cnpj-validador cnpj cpf cpf-validador brazilian-helpers telefone brazilian-validators validator</PackageTags>
<PackageTags>cnpj-validador cnpj cpf cpf-validador brazilian-helpersbrazilian-validators validator</PackageTags>
<PackageReleaseNotes>
- Remoção do tipo:
Cep
- Upgrade de versão do .net para .net 6
- Remoção de todos os tipos que não são CPF ou CNPJ.
</PackageReleaseNotes>
</PropertyGroup>

Expand Down

0 comments on commit 701d069

Please sign in to comment.