Last active
December 18, 2015 09:49
-
-
Save booyaa/5764242 to your computer and use it in GitHub Desktop.
Benchmarking in C#
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
| // Source: http://www.blackwasp.co.uk/SpeedTestWithStopwatch_2.aspx | |
| // Use it to compare things like da.Fills vs iterating over an OleDbDataReader. | |
| using System; | |
| using System.Diagnostics; | |
| namespace StopWatchExample | |
| { | |
| class Example | |
| { | |
| static void Main(string[] args) | |
| { | |
| Stopwatch timer = new Stopwatch(); | |
| long total = 0; | |
| timer.Start(); // Start the timer | |
| for (int i=1;i<=1000000;i++) | |
| { | |
| total += i; | |
| } | |
| timer.Stop(); // Stop the timer | |
| decimal micro = (decimal)timer.Elapsed.Ticks / 10M; // 10,000 microseconds in 1 millisecond | |
| Console.WriteLine("Execution time was {0:F1} microseconds.", micro); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment