Skip to content

Instantly share code, notes, and snippets.

@ro31337
Created February 11, 2015 16:36
Show Gist options
  • Select an option

  • Save ro31337/8be745dba280927d849f to your computer and use it in GitHub Desktop.

Select an option

Save ro31337/8be745dba280927d849f to your computer and use it in GitHub Desktop.
AutoFixture performance
using System;
using System.Diagnostics;
using Ploeh.AutoFixture;
namespace ConsoleApplication1
{
class Program // by Roman Pushkin - roman.pushkin/at/gmail
{
static void Main(string[] args)
{
var fixture = new Fixture();
var random = new Random();
Test(() => fixture.Create<string>());
Test(() => random.Next(1, 10000).ToString());
Test(() => Guid.NewGuid().ToString());
Console.ReadLine();
}
static void Test(Action action)
{
var watch = Stopwatch.StartNew();
for (int i = 0; i < 50000; i++)
{
action();
}
watch.Stop();
Console.WriteLine("Execution time: {0} ms", watch.ElapsedMilliseconds);
}
}
}
@ro31337

ro31337 commented Feb 11, 2015

Copy link
Copy Markdown
Author

Output for me:

Execution time: 947 ms
Execution time: 7 ms
Execution time: 39 ms

@jbogard

jbogard commented Feb 11, 2015

Copy link
Copy Markdown

My tests hit a database. That's 100-500ms for each test. For me, AutoFixture is a drop in the bucket.

When you run a suite of hundreds or thousands of tests, how much percentage of time is spent in AutoFixture versus everything else? That's what I'm more concerned about - optimizing for the whole. I would only care about AutoFixture if I proved with evidence that it was my bottleneck. From your numbers, it wouldn't be by several orders of magnitude.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment