Created
June 4, 2014 23:23
-
-
Save fekberg/ec4ba6ee6c61e2698010 to your computer and use it in GitHub Desktop.
Performance test for Ensure.That
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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