File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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
77Run all benchmarks on .NET 11:
88
You can’t perform that action at this time.
0 commit comments