Move jgit test code to its own project
[egit/zawir.git] / org.spearce.jgit.test / exttst / org / spearce / jgit / lib / T0005_ShallowSpeedTest.java
blobe6c43b944f51389c9ef60e5e9580fa90e073e719
1 /*
2 * Copyright (C) 2006 Robin Rosenberg <robin.rosenberg@dewire.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License, version 2.1, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 package org.spearce.jgit.lib;
19 import java.io.File;
20 import java.io.IOException;
22 import junit.textui.TestRunner;
24 public class T0005_ShallowSpeedTest extends SpeedTestBase {
26 protected void setUp() throws Exception {
27 prepare(new String[] { "git", "rev-list", "365bbe0d0caaf2ba74d56556827babf0bc66965d" });
30 public void testShallowHistoryScan() throws IOException {
31 long start = System.currentTimeMillis();
32 Repository db = new Repository(new File(kernelrepo));
33 Commit commit = db.mapCommit("365bbe0d0caaf2ba74d56556827babf0bc66965d");
34 int n = 1;
35 for (;;) {
36 ObjectId[] parents = commit.getParentIds();
37 if (parents.length == 0)
38 break;
39 ObjectId parentId = parents[0];
40 commit = db.mapCommit(parentId);
41 commit.getCommitId().toString();
42 ++n;
44 assertEquals(12275, n);
45 long stop = System.currentTimeMillis();
46 long time = stop - start;
47 System.out.println("native="+nativeTime);
48 System.out.println("jgit="+time);
49 // ~0.750s (hot cache), ok
51 native=1795
52 jgit=722
54 // native git seems to run SLOWER than jgit here, at roughly half the speed
55 // creating the git process is not the issue here, btw.
56 long factor10 = (nativeTime*150/time+50)/100;
57 assertEquals(3, factor10);
60 public static void main(String[] args) {
61 TestRunner.run(T0005_ShallowSpeedTest.class);