2 * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
3 * Copyright (C) 2007, Shawn O. Pearce <spearce@spearce.org>
7 * Redistribution and use in source and binary forms, with or
8 * without modification, are permitted provided that the following
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
19 * - Neither the name of the Git Development Community nor the
20 * names of its contributors may be used to endorse or promote
21 * products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 package org
.spearce
.jgit
.lib
;
41 import java
.io
.BufferedReader
;
43 import java
.io
.FileReader
;
44 import java
.io
.IOException
;
45 import java
.io
.InputStream
;
47 import junit
.framework
.TestCase
;
50 * Base class for performance unit test.
52 public abstract class SpeedTestBase
extends TestCase
{
55 * The time used by native git as this is our reference.
57 protected long nativeTime
;
60 * Reference to the location of the Linux kernel repo.
62 protected String kernelrepo
;
65 * Prepare test by running a test against the Linux kernel repo first.
68 * git command to execute
72 protected void prepare(String
[] refcmd
) throws Exception
{
74 BufferedReader bufferedReader
= new BufferedReader(new FileReader("kernel.ref"));
76 kernelrepo
= bufferedReader
.readLine();
77 bufferedReader
.close();
78 timeNativeGit(kernelrepo
, refcmd
);
79 nativeTime
= timeNativeGit(kernelrepo
, refcmd
);
81 bufferedReader
.close();
83 } catch (Exception e
) {
84 System
.out
.println("Create a file named kernel.ref and put the path to the Linux kernels repository there");
89 private static long timeNativeGit(String kernelrepo
, String
[] refcmd
) throws IOException
,
90 InterruptedException
, Exception
{
91 long start
= System
.currentTimeMillis();
92 Process p
= Runtime
.getRuntime().exec(refcmd
, null, new File(kernelrepo
,".."));
93 InputStream inputStream
= p
.getInputStream();
94 InputStream errorStream
= p
.getErrorStream();
95 byte[] buf
=new byte[1024*1024];
97 if (inputStream
.read(buf
) < 0)
101 while ((c
=errorStream
.read())!=-1)
102 System
.err
.print((char)c
);
103 throw new Exception("git log failed");
107 long stop
= System
.currentTimeMillis();