Skip to content

Instantly share code, notes, and snippets.

@pictos
Created July 17, 2023 18:41
Show Gist options
  • Save pictos/aed57c3a971300f2be4f03f7f3ab847a to your computer and use it in GitHub Desktop.
Save pictos/aed57c3a971300f2be4f03f7f3ab847a to your computer and use it in GitHub Desktop.
someBenchmarkCode
using BenchmarkDotNet.Attributes;
namespace GeneralBench;
public record Registro
{
public required string Nome { get; init; }
public int Total { get; init; }
}
[MemoryDiagnoser]
[RankColumn]
public class Pessoa
{
private List<Registro> _registros = new(13)
{
new() { Nome = "Maria", Total = 133569652 },
new() { Nome = "José", Total = 77815153 },
new() { Nome = "Antônio ", Total = 35507524 },
new() { Nome = "João", Total = 29887445 },
new() { Nome = "Francisco", Total = 22421466 },
new() { Nome = "Ana", Total = 19963777 },
new() { Nome = "Luiz ", Total = 15418958 },
new() { Nome = "Paulo", Total = 14167689 },
new() { Nome = "Carlos ", Total = 138420110 },
new() { Nome = "Manoel", Total = 133418211 },
new() { Nome = "Pedro ", Total = 99525412 },
new() { Nome = "Francisca", Total = 85359013 },
new() { Nome = "Raimundo ", Total = 82124215 }
};
[Benchmark]
public void PegarComFirst()
{
_ = _registros.First();
}
[Benchmark]
public void PegarPeloIndex()
{
_ = _registros[0];
}
[Benchmark]
public Registro PegarComFirstMeu()
{
return _registros.First();
}
[Benchmark]
public Registro PegarPeloIndexMeu()
{
return _registros[0];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment