Click here to Skip to main content
15,886,847 members
Articles / Programming Languages / C#

Generic DFA State Machine for .NET

Rate me:
Please Sign up or sign in to vote.
4.75/5 (42 votes)
21 May 2003BSD6 min read 224.3K   3.6K   75  
Seemless NFA to DFA transfers with GraphViz graphing integration
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Threading;

namespace leppie
{
   internal class HiPerfTimer
   {
      [DllImport("Kernel32.dll")]
      private static extern bool QueryPerformanceCounter(ref long lpPerformanceCount);

      [DllImport("Kernel32.dll")]
      private static extern bool QueryPerformanceFrequency(ref long lpFrequency);

      private long startTime, stopTime;
      private long freq;

      // Constructor
      public HiPerfTimer()
      {
         startTime = 0;
         stopTime  = 0;

         if (!QueryPerformanceFrequency(ref freq))
         {
            // high-performance counter not supported
            throw new Win32Exception();
         }
      }

      // Start the timer
      public void Start()
      {
         // lets do the waiting threads there work
         Thread.Sleep(0);

         QueryPerformanceCounter(ref startTime);
      }

      // Stop the timer
      public void Stop()
      {
         QueryPerformanceCounter(ref stopTime);
      }

      // Returns the duration of the timer (in milliseconds)
      public double Duration
      {
         get
         {
            return (double)(stopTime - startTime) / freq * 1000F;
         }
      }
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Software Developer
South Africa South Africa
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions