Skip to content

Instantly share code, notes, and snippets.

@kellabyte
Created January 21, 2012 01:14
Show Gist options
  • Select an option

  • Save kellabyte/1650586 to your computer and use it in GitHub Desktop.

Select an option

Save kellabyte/1650586 to your computer and use it in GitHub Desktop.
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