Created
January 21, 2012 01:14
-
-
Save kellabyte/1650586 to your computer and use it in GitHub Desktop.
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 System.Globalization; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| namespace TweetStreamTest | |
| { | |
| public class FastLoopTest | |
| { | |
| private static double count = 0; | |
| private static Stopwatch watch = null; | |
| private static int threadCount = 4; | |
| private static Timer timer; | |
| public void Start() | |
| { | |
| watch = new Stopwatch(); | |
| watch.Start(); | |
| timer = new Timer(Timer_Callback, null, 0, 1000); | |
| int i = 1; | |
| while (i <= threadCount) | |
| { | |
| Console.WriteLine("Creating thread " + i); | |
| Task.Factory.StartNew(() => | |
| { | |
| Loop(); | |
| }); | |
| i++; | |
| } | |
| } | |
| private void Loop() | |
| { | |
| while (true) | |
| { | |
| count++; | |
| } | |
| } | |
| private static void Timer_Callback(object state) | |
| { | |
| if (watch != null) | |
| { | |
| double rate = count / watch.Elapsed.TotalSeconds; | |
| Console.WriteLine("{0}\t{1}", | |
| count.ToString("0,0", CultureInfo.InvariantCulture), | |
| ((int)rate).ToString("0,0", CultureInfo.InvariantCulture)); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment