Permalink
Browse files

Improved benchmarks.

  • Loading branch information...
1 parent d9d123d commit dbaa8bb20a9a6fd5d4cdb29ebe2c6c4cc90f41cd Matt Burke committed Dec 15, 2009
Showing with 50 additions and 21 deletions.
  1. +13 −2 GitTfsBenchmarks/Benchmark.cs
  2. +37 −19 GitTfsBenchmarks/Benchmarks/HashAndInsertObject.cs
@@ -23,6 +23,7 @@
// THE SOFTWARE.
using System;
+using System.Collections.Generic;
using System.Reflection;
using System.Collections;
@@ -65,6 +66,8 @@ public static void Main(string[] args)
// just makes it easier to read the code...
BindingFlags publicStatic = BindingFlags.Public | BindingFlags.Static;
+ var exceptions = new List<Exception>();
+
foreach (Type type in typeof(Benchmark).Assembly.GetTypes())
{
// Find an Init method taking string[], if any
@@ -141,6 +144,7 @@ public static void Main(string[] args)
foreach (MethodInfo method in benchmarkMethods)
{
+ var shouldCleanUpOnFailure = true;
try
{
// Reset (if appropriate)
@@ -168,6 +172,7 @@ public static void Main(string[] args)
}
// Clean up (if appropriate)
+ shouldCleanUpOnFailure = false;
if (cleanupMethod != null)
{
cleanupMethod.Invoke(null, null);
@@ -180,22 +185,28 @@ public static void Main(string[] args)
catch (TargetInvocationException e)
{
Exception inner = e.InnerException;
+ exceptions.Add(inner ?? e);
string message = (inner == null ? null : inner.Message);
if (message == null)
{
message = "(No message)";
}
- Console.WriteLine(" {0}: Failed ({1})", method.Name, message);
+ Console.WriteLine(" {0}: Failed ({1}) [{2}]", method.Name, message, exceptions.Count);
// Clean up (if appropriate)
- if (cleanupMethod != null)
+ if (shouldCleanUpOnFailure && cleanupMethod != null)
{
cleanupMethod.Invoke(null, null);
}
}
}
}
}
+ for (var i = 0; i < exceptions.Count; i++)
+ {
+ Console.WriteLine();
+ Console.WriteLine("[" + (i + 1) + "] " + exceptions[i]);
+ }
}
/// <summary>
@@ -1,19 +1,33 @@
using System;
-using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Security.Cryptography;
using System.Text;
-using System.Text.RegularExpressions;
using GitSharp.Core;
+using SEP.Extensions;
using Sep.Git.Tfs.Core;
using Sep.Git.Tfs.Util;
namespace Sep.Git.Tfs.Benchmarks
{
class HashAndInsertObject
{
+ class TestGitObject
+ {
+ public string ObjectId { get; set; }
+ public string Contents { get; set; }
+ public string ObjectPath { get { return ".git/objects/" + ObjectId.Substring(0, 2) + "/" + ObjectId.Substring(2); } }
+ }
+
+ private static readonly List<TestGitObject> TestObjects = new List<TestGitObject>
+ {
+ new TestGitObject
+ {
+ ObjectId = "0e44708cb3166a9f6c5c0a038bc7b2c0c2435e13",
+ Contents = "teststring\r\nanother line\rafter just r\nafter just n"
+ }
+ };
private static readonly GitHelpers gitHelper = new GitHelpers(TextWriter.Null);
#region WithPureDotNet
@@ -128,26 +142,28 @@ public static void Cleanup()
public static void Check()
{
- foreach (var file in GetExpectedFiles())
+ foreach (var testObject in TestObjects)
{
- if (!File.Exists(file))
+ if (!File.Exists(testObject.ObjectPath))
+ {
+ throw new Exception("Expected file " + testObject.ObjectPath + " was not found!");
+ }
+ try
+ {
+ var objectContents = gitHelper.Command("show", testObject.ObjectId);
+ if(objectContents != testObject.Contents)
+ {
+ throw new Exception("Expected object " + testObject.ObjectId + " to be " + testObject.Contents.Inspect() +
+ " but it was " + objectContents.Inspect());
+ }
+ }
+ catch (GitCommandException e)
{
- throw new Exception("Expected file " + file + " was not found!");
+ throw new Exception("Unable to read object " + testObject.ObjectId + ".", e);
}
}
}
- private static IEnumerable<string> GetExpectedFiles()
- {
- yield return ".git/objects/0e/44708cb3166a9f6c5c0a038bc7b2c0c2435e13";
- }
-
- private static IEnumerable<string> Split(string files)
- {
- var regex = new Regex("\\s+");
- return regex.Split(files);
- }
-
private static void Run(string name, Func<Stream, string> hashAndStore)
{
var dirName = Path.Combine(Environment.CurrentDirectory, "hash-object-" + name);
@@ -156,10 +172,12 @@ private static void Run(string name, Func<Stream, string> hashAndStore)
Environment.CurrentDirectory = dirName;
gitHelper.CommandNoisy("init");
- for (int i = 0; i < 300; i++)
+ foreach (var testObject in TestObjects)
{
- hashAndStore(
- MakeMemoryStream("teststring\r\nanother line\rafter just r\nafter just n"));
+ for (int i = 0; i < 300; i++)
+ {
+ hashAndStore(MakeMemoryStream(testObject.Contents));
+ }
}
}

0 comments on commit dbaa8bb

Please sign in to comment.