/////////////////////////////////////////////////////////////////////// public void Start( long iterations ) { Reset(false); this.iterations += iterations; startCount = PerformanceOps.GetCount(); }
public static void Start( ref long startCount, /* out */ ref double microseconds /* in, out */ ) { microseconds = 0; startCount = PerformanceOps.GetCount(); }
/////////////////////////////////////////////////////////////////////// public static void Stop( long startCount, /* in */ ref long stopCount, /* out */ ref double microseconds /* in, out */ ) { stopCount = PerformanceOps.GetCount(); microseconds += PerformanceOps.GetMicroseconds( startCount, stopCount, 1); }
/////////////////////////////////////////////////////////////////////// public void Stop() { stopCount = PerformanceOps.GetCount(); microseconds += PerformanceOps.GetMicroseconds( startCount, stopCount, iterations); if (!quiet) { Report(); } }
/////////////////////////////////////////////////////////////////////// public static ReturnCode Wait( Interpreter interpreter, long microseconds, bool timeout, bool strict, ref Result error ) /* THREAD-SAFE */ { ReturnCode code = ReturnCode.Ok; if (interpreter != null) { int waitCount; if ((waitCount = interpreter.EnterWait()) > 0) { if (microseconds == 0) { #if WINFORMS // // NOTE: If necessary, process all Windows messages // from the queue. // if (!strict) { code = WindowOps.ProcessEvents( interpreter, ref error); } if (code == ReturnCode.Ok) #endif { // // NOTE: Yield to other running threads. This // also gives them an opportunity to cancel // the script in progress on this thread. // HostOps.Yield(); } } else { // // NOTE: Keep track of how many iterations through // the loop we take. // int iterations = 0; // // HACK: Account for our processing overhead; use half // of the requested delay. // int milliseconds = ConversionOps.ToInt( PerformanceOps.GetMilliseconds(microseconds) / WaitDivisor); if (milliseconds < 0) { milliseconds = 0; } if (milliseconds > WaitMaximumSleepTime) { milliseconds = WaitMaximumSleepTime; } // // NOTE: For more precise timing, use the high-resolution // CPU performance counter. // long startCount = PerformanceOps.GetCount(); // // BUGFIX: Make sure the slop time does not exceed the // actual wait. // long slopMicroseconds = Math.Min( microseconds / WaitSlopDivisor, WaitSlopMinimumTime); // // NOTE: Delay for approximately the specified number of // microseconds, optionally timing out if we cannot // obtain the interpreter lock before the time period // elapses. // while (((code = Interpreter.EventReady(interpreter, timeout ? milliseconds : _Timeout.Infinite, ref error)) == ReturnCode.Ok) && !PerformanceOps.HasElapsed(startCount, microseconds, slopMicroseconds)) { #if WINFORMS if (!strict) { code = WindowOps.ProcessEvents(interpreter, ref error); if (code != ReturnCode.Ok) { break; } } #endif HostOps.SleepOrMaybeComplain(interpreter, milliseconds); iterations++; } long stopCount = PerformanceOps.GetCount(); double elapsedMicroseconds = PerformanceOps.GetMicroseconds( startCount, stopCount, 1); TraceOps.DebugTrace(String.Format( "Wait: code = {0}, iterations = {1}, microseconds = {2}, " + "elapsedMicroseconds = {3}, sleepMilliseconds = {4}, " + "slopMicroseconds = {5}, differenceMicroseconds = {6}, " + "waitCount = {7}, error = {8}", code, iterations, microseconds, elapsedMicroseconds, milliseconds, slopMicroseconds, elapsedMicroseconds - (double)microseconds, waitCount, FormatOps.WrapOrNull(true, true, error)), typeof(EventOps).Name, TracePriority.EventDebug); } /* IGNORED */ interpreter.ExitWait(); } else { error = "wait subsystem locked"; code = ReturnCode.Error; } } else { error = "invalid interpreter"; code = ReturnCode.Error; } return(code); }