@@ -0,0 +1,3333 @@
+package jmh.benchmark;%0A%0Aimport hudson.EnvVars;%0Aimport hudson.model.TaskListener;%0Aimport org.eclipse.jgit.lib.ObjectId;%0Aimport org.jenkinsci.plugins.gitclient.Git;%0Aimport org.jenkinsci.plugins.gitclient.GitClient;%0Aimport org.openjdk.jmh.annotations.*;%0Aimport org.openjdk.jmh.infra.Blackhole;%0A%0Aimport java.io.File;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Apublic class GitClientLSRemoteBenchmark %7B%0A%0A    @State(Scope.Thread)%0A    public static class ClientState %7B%0A%0A        @Param(%7B%22git%22, %22jgit%22%7D)%0A        String gitExe;%0A%0A        @Param(%7B%22https://github.com/jenkinsci/ec2-plugin.git%22,%0A                %22https://github.com/jenkinsci/git-client-plugin.git%22,%0A                %22https://github.com/jenkinsci/jenkins.git%22,%0A                %22https://github.com/ruby/ruby.git%22,%0A                %22https://github.com/kubernetes/kubernetes.git%22%7D)%0A        String repositoryURL;%0A%0A        final FolderForBenchmark tmp = new FolderForBenchmark();%0A        File gitDir;%0A        GitClient gitClient;%0A        Map%3CString, ObjectId%3E remoteReferences;%0A%0A        /**%0A         * We want to create a temporary local git repository after each iteration of the benchmark, works just like%0A         * %22before%22 and %22after%22 JUnit annotations.%0A         */%0A        @Setup(Level.Iteration)%0A        public void doSetup() throws Exception %7B%0A            tmp.before();%0A            gitDir = tmp.newFolder();%0A%0A            gitClient = Git.with(TaskListener.NULL, new EnvVars()).in(gitDir).using(gitExe).getClient();%0A            remoteReferences = new HashMap%3C%3E();%0A%0A            System.out.println(%22Do Setup for: %22 + gitExe);%0A        %7D%0A%0A        @TearDown(Level.Iteration)%0A        public void doTearDown() %7B%0A            try %7B%0A                // making sure that git init made a git an empty repository%0A                File gitDir = gitClient.withRepository((repo, channel) -%3E repo.getDirectory());%0A                System.out.println(gitDir.isDirectory());%0A            %7D catch (Exception e) %7B%0A                e.getMessage();%0A            %7D%0A            tmp.after();%0A            System.out.println(%22Do TearDown for: %22 + gitExe);%0A        %7D%0A%0A        public boolean validateReferences(String gitURL, int numberOfRefs) %7B%0A            switch (gitURL) %7B%0A                case %22https://github.com/jenkinsci/ec2-plugin.git%22:%0A                    return numberOfRefs %3E= 696;%0A                case %22https://github.com/jenkinsci/git-client-plugin.git%22:%0A                    return numberOfRefs %3E= 836;%0A                case %22https://github.com/jenkinsci/jenkins.git%22:%0A                    return numberOfRefs %3E= 7137;%0A                case %22https://github.com/ruby/ruby.git%22:%0A                    return numberOfRefs %3E= 6308;%0A                case %22https://github.com/kubernetes/kubernetes.git%22:%0A                    return numberOfRefs %3E= 88027;%0A            %7D%0A            return false;%0A        %7D%0A    %7D%0A%0A    @Benchmark%0A    public void gitlsremoteBenchmark(ClientState clientState, Blackhole blackhole) throws Exception %7B%0A        clientState.remoteReferences = clientState.gitClient.getRemoteReferences(clientState.repositoryURL, null, false, false);%0A        if (clientState.validateReferences(clientState.repositoryURL, clientState.remoteReferences.keySet().size())) %7B%0A            blackhole.consume(clientState.remoteReferences);%0A        %7D%0A        blackhole.consume(clientState.remoteReferences);%0A    %7D%0A%7D%0A

Add a benchmark for git ls-remote The benchmark performs a git ls-remote on remote repositories which are chosen with incremental number of references. This benchmark interacts with remote repositories over network instead of a local git repository.