コード例 #1
0
        void NotificationTimer(ref long timerIntervalInMicroSec,
                               ref long ignoreEventIfLateBy,
                               ref bool stopTimer)
        {
            int  timerCount       = 0;
            long nextNotification = 0;

            MicroStopwatch microStopwatch = new MicroStopwatch();

            microStopwatch.Start();

            while (!stopTimer)
            {
                long callbackFunctionExecutionTime =
                    microStopwatch.ElapsedMicroseconds - nextNotification;

                long timerIntervalInMicroSecCurrent =
                    System.Threading.Interlocked.Read(ref timerIntervalInMicroSec);
                long ignoreEventIfLateByCurrent =
                    System.Threading.Interlocked.Read(ref ignoreEventIfLateBy);

                nextNotification += timerIntervalInMicroSecCurrent;
                timerCount++;
                long elapsedMicroseconds = 0;

                // https://www.codeproject.com/Articles/98346/Microsecond-and-Millisecond-NET-Timer?msg=5288003#xx5288003xx
                //while ( (elapsedMicroseconds = microStopwatch.ElapsedMicroseconds)
                //        < nextNotification)
                //{
                //    System.Threading.Thread.SpinWait(10);
                //}
                int wms = (int)timerIntervalInMicroSec / 1000;
                wms = wms - (int)(wms * 0.01);
                _threadTimer.Join(wms);
                while ((elapsedMicroseconds = microStopwatch.ElapsedMicroseconds) < nextNotification)
                {
                    System.Threading.Thread.SpinWait(10);
                }


                long timerLateBy = elapsedMicroseconds - nextNotification;

                if (timerLateBy >= ignoreEventIfLateByCurrent)
                {
                    continue;
                }

                MicroTimerEventArgs microTimerEventArgs =
                    new MicroTimerEventArgs(timerCount,
                                            elapsedMicroseconds,
                                            timerLateBy,
                                            callbackFunctionExecutionTime);
                MicroTimerElapsed(this, microTimerEventArgs);
            }

            microStopwatch.Stop();
        }
コード例 #2
0
        void NotificationTimer(ref long timerIntervalInMicroSec,
                               ref long ignoreEventIfLateBy,
                               ref bool stopTimer)
        {
            int  timerCount       = 0;
            long nextNotification = 0;

            MicroStopwatch microStopwatch = new MicroStopwatch();

            microStopwatch.Start();

            while (!stopTimer)
            {
                long callbackFunctionExecutionTime =
                    microStopwatch.ElapsedMicroseconds - nextNotification;

                long timerIntervalInMicroSecCurrent =
                    System.Threading.Interlocked.Read(ref timerIntervalInMicroSec);
                long ignoreEventIfLateByCurrent =
                    System.Threading.Interlocked.Read(ref ignoreEventIfLateBy);

                nextNotification += timerIntervalInMicroSecCurrent;
                timerCount++;
                long elapsedMicroseconds = 0;

                while ((elapsedMicroseconds = microStopwatch.ElapsedMicroseconds)
                       < nextNotification)
                {
                    //System.Threading.Thread.SpinWait(10);
                    System.Threading.Thread.Sleep(1);
                }

                long timerLateBy = elapsedMicroseconds - nextNotification;

                //if (timerLateBy >= ignoreEventIfLateByCurrent)
                //{
                //    nextNotification += timerIntervalInMicroSecCurrent;
                //}
                //else
                {
                    MicroTimerEventArgs microTimerEventArgs =
                        new MicroTimerEventArgs(timerCount,
                                                elapsedMicroseconds,
                                                timerLateBy,
                                                callbackFunctionExecutionTime);
                    MicroTimerElapsed(this, microTimerEventArgs);
                }
            }

            microStopwatch.Stop();
        }
コード例 #3
0
        void NotificationTimer(long timerInterval,
                               long ignoreEventIfLateBy,
                               ref bool stopTimer)
        {
            int  timerCount       = 0;
            long nextNotification = 0;

            MicroStopwatch microStopwatch = new MicroStopwatch();

            microStopwatch.Start();

            while (!stopTimer)
            {
                long callbackFunctionExecutionTime =
                    microStopwatch.ElapsedMicroseconds - nextNotification;
                nextNotification += timerInterval;
                timerCount++;
                long elapsedMicroseconds = 0;

                while ((elapsedMicroseconds = microStopwatch.ElapsedMicroseconds)
                       < nextNotification)
                {
                    System.Threading.Thread.SpinWait(10);
                }

                long timerLateBy = elapsedMicroseconds - (timerCount * timerInterval);

                if (timerLateBy >= ignoreEventIfLateBy)
                {
                    continue;
                }

                MicroTimerEventArgs microTimerEventArgs =
                    new MicroTimerEventArgs(timerCount,
                                            elapsedMicroseconds,
                                            timerLateBy,
                                            callbackFunctionExecutionTime);
                MicroTimerElapsed(this, microTimerEventArgs);
            }

            microStopwatch.Stop();
        }
コード例 #4
0
ファイル: MicroLibrary.cs プロジェクト: collin80/GVRET-PC
        void NotificationTimer(ref long timerIntervalInMicroSec,
                               ref long ignoreEventIfLateBy,
                               ref bool stopTimer)
        {
            int  timerCount = 0;
            long nextNotification = 0;

            MicroStopwatch microStopwatch = new MicroStopwatch();
            microStopwatch.Start();

            while (!stopTimer)
            {
                long callbackFunctionExecutionTime =
                    microStopwatch.ElapsedMicroseconds - nextNotification;

                long timerIntervalInMicroSecCurrent =
                    System.Threading.Interlocked.Read(ref timerIntervalInMicroSec);
                long ignoreEventIfLateByCurrent =
                    System.Threading.Interlocked.Read(ref ignoreEventIfLateBy);

                nextNotification += timerIntervalInMicroSecCurrent;
                timerCount++;
                long elapsedMicroseconds = 0;

                while ( (elapsedMicroseconds = microStopwatch.ElapsedMicroseconds)
                        < nextNotification)
                {
                    System.Threading.Thread.SpinWait(10);
                }

                long timerLateBy = elapsedMicroseconds - nextNotification;

                if (timerLateBy >= ignoreEventIfLateByCurrent)
                {
                    continue;
                }

                MicroTimerEventArgs microTimerEventArgs =
                     new MicroTimerEventArgs(timerCount,
                                             elapsedMicroseconds,
                                             timerLateBy,
                                             callbackFunctionExecutionTime);
                MicroTimerElapsed(this, microTimerEventArgs);
            }

            microStopwatch.Stop();
        }
コード例 #5
0
ファイル: Gameboy.cs プロジェクト: RykoL/geekboy
        private void _MainCycle()
        {
            MicroStopwatch mw = new MicroStopwatch();
            int cycToGo = 0;
            while (true)
            {
                mw.Start();

                for (int i = 0; i < 4; i++)
                {
                    HandleInterrupts();
                    if (cycToGo == 0)
                    {
                        cycToGo = Cpu.ExecuteOp() - 1;
                    } else {
                        cycToGo--;
                    }
                    Video.ModeClock++;
                    HandleVideo();
                }

                timer.Tick();
                Audio.Tick();

                while (mw.ElapsedMicroseconds == 0) ;
                mw.Reset();
            }
        }
コード例 #6
0
 public MicroTimerStrategy()
 {
     mTimer = new MicroStopwatch();
 }
コード例 #7
0
ファイル: RedisTest.cs プロジェクト: zoldham/RedisPOC
    static StreamWriter logWriter = new StreamWriter(logFile);                                                              // The logging stream

    /*
     * Program entry point
     */
    static void Main(string[] args)
    {
        logWriter.AutoFlush = true;

        // Get access to sql
        string        connectionString = "Data Source=tcp:172.30.100.116;\n;Initial Catalog=GlobalDeviceService;\nUser ID=octopus;Password=octopus";
        SqlConnection cnn = new SqlConnection(connectionString);

        cnn.Open();

        // Load the queries
        string[] graphqlQueries = get_queries(numGraphQLQueries, GraphQLFolder);
        string[] sqlQueries     = get_queries(numSQLQueries, SQLFolder);

        // Process and time the queries for Graphql
        do_logging_writeline("Beginning GraphQL Tests\n");
        for (int i = 0; i < numGraphQLQueries && !String.IsNullOrEmpty(graphqlQueries[i]); i++)
        {
            // Do logging, start timer
            string curQuery = graphqlQueries[i];
            do_logging_writeline("Current Query: ");
            do_logging_write(curQuery + "\n\n");
            MicroLibrary.MicroStopwatch timer = new MicroLibrary.MicroStopwatch();

            // Get the result into the cache
            do_graphql_query_caching(curQuery).GetAwaiter().GetResult();

            // Time the query (cached) and sum the execution times
            long cachedTime = 0;
            for (int j = 0; j < numExecutions; j++)
            {
                // Time the call and aggregate
                timer.Restart();
                do_graphql_query_caching(curQuery).GetAwaiter().GetResult();
                timer.Stop();
                cachedTime += timer.ElapsedMicroseconds;
            }

            // Cleanup
            db.KeyDelete(curQuery);

            // Time the query (uncached) and sum the execution times
            long uncachedTime = 0;
            for (int j = 0; j < numExecutions; j++)
            {
                // Time the call and aggregate
                timer.Restart();
                do_graphql_query_no_caching(curQuery).GetAwaiter().GetResult();
                timer.Stop();
                uncachedTime += timer.ElapsedMicroseconds;
            }

            do_logging_writeline("Uncached execution time (Average of " + numExecutions.ToString() + " runs): " + (uncachedTime / numExecutions).ToString() + "µs");
            do_logging_writeline("Cached execution time (Average of " + numExecutions.ToString() + " runs): " + (cachedTime / numExecutions).ToString() + "µs");
            do_logging_writeline(((double)(uncachedTime / numExecutions) / (double)(cachedTime / numExecutions)).ToString() + " times faster.\n");
            //do_logging_writeline("Size of result set: " + result.Length.ToString() + "\n");
        }

        // Process and time the queries for SQL Server
        do_logging_writeline("\nBeginning SQL Tests\n");
        for (int i = 0; i < numSQLQueries && !String.IsNullOrEmpty(sqlQueries[i]); i++)
        {
            //Do logging, start timer
            string curQuery = sqlQueries[i];
            do_logging_writeline("Current Query: ");
            do_logging_write(curQuery + "\n\n");
            MicroLibrary.MicroStopwatch timer = new MicroLibrary.MicroStopwatch();

            // Get the result into the cache
            do_sql_query_caching(curQuery, cnn).GetAwaiter().GetResult();

            // Time the query (cached) and sum the execution times
            long cachedTime = 0;
            for (int j = 0; j < numExecutions; j++)
            {
                // Time the call and aggregate
                timer.Restart();
                do_sql_query_caching(curQuery, cnn).GetAwaiter().GetResult();
                timer.Stop();
                cachedTime += timer.ElapsedMicroseconds;
            }

            // Cleanup
            db.KeyDelete(curQuery);

            // Time the query (uncached) and sum the execution times
            long uncachedTime = 0;
            for (int j = 0; j < numExecutions; j++)
            {
                // Time the call and aggregate
                timer.Restart();
                do_sql_query_no_caching(curQuery, cnn).GetAwaiter().GetResult();
                timer.Stop();
                uncachedTime += timer.ElapsedMicroseconds;
            }

            do_logging_writeline("Uncached execution time (Average of " + numExecutions.ToString() + " runs): " + (uncachedTime / numExecutions).ToString() + "µs");
            do_logging_writeline("Cached execution time (Average of " + numExecutions.ToString() + " runs): " + (cachedTime / numExecutions).ToString() + "µs");
            do_logging_writeline(((double)(uncachedTime / numExecutions) / (double)(cachedTime / numExecutions)).ToString() + " times faster.\n");
            //do_logging_writeline("Size of result set: " + result.Length.ToString() + "\n");
        }

        // cleanup
        cnn.Close();
    }