Created
February 11, 2015 16:36
-
-
Save ro31337/8be745dba280927d849f to your computer and use it in GitHub Desktop.
AutoFixture performance
This file contains hidden or 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.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); | |
| } | |
| } | |
| } |
Author
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
Output for me:
Execution time: 947 ms
Execution time: 7 ms
Execution time: 39 ms