Skip to content

Commit ba1e9b7

Browse files
committed
Add commit lookup benchmark
Looks up 1,000 commits by id, which passes each id to libgit2 as a ref GitOid.
1 parent 9c06972 commit ba1e9b7

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System.Linq;
2+
using BenchmarkDotNet.Attributes;
3+
4+
namespace LibGit2Sharp.Benchmarks
5+
{
6+
/// <summary>
7+
/// Every lookup passes the id to libgit2 as a ref GitOid.
8+
/// </summary>
9+
[MemoryDiagnoser]
10+
public class LookupBenchmarks
11+
{
12+
TempRepository repo;
13+
ObjectId[] ids;
14+
15+
[Params(1000)]
16+
public int CommitCount { get; set; }
17+
18+
[GlobalSetup]
19+
public void Setup()
20+
{
21+
repo = new TempRepository();
22+
23+
for (var i = 0; i < CommitCount; i++)
24+
{
25+
repo.Commit("file.txt", i.ToString(), $"Commit {i}");
26+
}
27+
28+
ids = repo.Repository.Commits.Select(c => c.Id).ToArray();
29+
}
30+
31+
[GlobalCleanup]
32+
public void Cleanup()
33+
{
34+
repo.Dispose();
35+
}
36+
37+
[Benchmark]
38+
public int LookupCommits()
39+
{
40+
var count = 0;
41+
42+
foreach (var id in ids)
43+
{
44+
if (repo.Repository.Lookup<Commit>(id) != null)
45+
{
46+
count++;
47+
}
48+
}
49+
50+
return count;
51+
}
52+
}
53+
}

‎LibGit2Sharp.Benchmarks/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[BenchmarkDotNet](https://benchmarkdotnet.org/) benchmarks for LibGit2Sharp. Every benchmark reports allocations.
44

5-
The diff and commit walk benchmarks build a throwaway repository under the temp folder in their setup and delete it afterwards.
5+
The diff, commit walk and lookup benchmarks build a throwaway repository under the temp folder in their setup and delete it afterwards.
66

77
Run all benchmarks on .NET 11:
88

0 commit comments

Comments
 (0)