Skip to content

Instantly share code, notes, and snippets.

@fekberg
Created June 4, 2014 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fekberg/ec4ba6ee6c61e2698010 to your computer and use it in GitHub Desktop.
Save fekberg/ec4ba6ee6c61e2698010 to your computer and use it in GitHub Desktop.
Performance test for Ensure.That
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EnsureThat.Performance
{
class Program
{
public static string Test { get; set; }
static void Main(string[] args)
{
Test = "test";
var stopwatch = new Stopwatch();
// Warm up
Console.WriteLine("Warm up start");
for (var i = 0; i < 100000; i++)
for (var a = 0; i < 100000; i++) ;
Console.WriteLine("Warm up complete");
GC.Collect();
GC.WaitForFullGCComplete(1000000);
Console.WriteLine("Ensure.That Expression");
stopwatch.Start();
for (var i = 0; i < 100000; i++)
{
Ensure.That(_ => Test).IsNotNullOrWhiteSpace();
}
stopwatch.Stop();
Console.WriteLine("Ensure.That Expression ran for {0}ms", stopwatch.ElapsedMilliseconds);
GC.Collect();
GC.WaitForFullGCComplete(1000000);
Console.WriteLine("Ensure.That Normal");
stopwatch.Reset();
stopwatch.Start();
for (var i = 0; i < 100000; i++)
{
Ensure.That(Test, "Test").IsNotNullOrWhiteSpace();
}
stopwatch.Stop();
Console.WriteLine("Ensure.That Normal ran for {0}ms", stopwatch.ElapsedMilliseconds);
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment