本文整理汇总了C#中System.Diagnostics.Stopwatch.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# System.Diagnostics.Stopwatch.Reset方法的具体用法?C# System.Diagnostics.Stopwatch.Reset怎么用?C# System.Diagnostics.Stopwatch.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Stopwatch
的用法示例。
在下文中一共展示了System.Diagnostics.Stopwatch.Reset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MeasureStopwatch
public void MeasureStopwatch()
{
var sw = new System.Diagnostics.Stopwatch();
var measured = new System.Diagnostics.Stopwatch();
sw.Reset();
sw.Start();
measured.Start();
measured.Stop();
var warmupTemp = measured.ElapsedMilliseconds;
sw.Stop();
var warmupTime = sw.ElapsedMilliseconds;
measured.Reset();
sw.Reset();
sw.Start();
sw.Stop();
var originalTime = sw.ElapsedMilliseconds;
sw.Reset();
sw.Start();
for (var i = 0; i < 1000000; i++)
{
measured.Start();
measured.Stop();
var temp = measured.ElapsedMilliseconds;
}
sw.Stop();
var measuredTime = sw.ElapsedMilliseconds;
Console.WriteLine(measuredTime - originalTime);
}
示例2: Main
static void Main(string[] args)
{
string s = System.IO.File.ReadAllText(@"example.json");
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
for (int i = 0; i < 10000; i++)
Fairytale.JsonDeserializer.Deserialize(s);
sw.Stop();
Console.WriteLine(sw.Elapsed);
sw.Reset();
sw.Start();
for (int i = 0; i < 10000; i++)
Newtonsoft.Json.JsonConvert.DeserializeObject(s);
sw.Stop();
Console.WriteLine(sw.Elapsed);
sw.Reset();
sw.Start();
var parser = new System.Text.Json.JsonParser();
for (int i = 0; i < 10000; i++)
parser.Parse(s);
sw.Stop();
Console.WriteLine(sw.Elapsed);
Console.ReadLine();
}
示例3: WorkerEvents
static private void WorkerEvents()
{
Tuple<EventDelegate, IPlugin> cEvent;
System.Diagnostics.Stopwatch cWatch = new System.Diagnostics.Stopwatch();
while (true)
{
try
{
cEvent = _aqEvents.Dequeue();
cWatch.Reset();
cWatch.Restart();
cEvent.Item1(cEvent.Item2);
cWatch.Stop();
if (40 < cWatch.ElapsedMilliseconds)
(new Logger()).WriteDebug3("duration: " + cWatch.ElapsedMilliseconds + " queue: " + _aqEvents.nCount);
if (0 < _aqEvents.nCount)
(new Logger()).WriteDebug3(" queue: " + _aqEvents.nCount);
}
catch (System.Threading.ThreadAbortException)
{
break;
}
catch (Exception ex)
{
(new Logger()).WriteError(ex);
}
}
}
示例4: Main
static void Main()
{
Scene scene = new Scene();
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
watch.Start();
GameTime time = new GameTime();
MessagePump.Run(scene.GraphicsEngine.Form, () =>
{
watch.Reset();
watch.Start();
int frameTime = 1;
if (time.LastFrameElapsedTime.TotalMilliseconds < frameTime)
System.Threading.Thread.Sleep((int)(frameTime - time.LastFrameElapsedTime.TotalMilliseconds));
scene.Update(time);
scene.Draw();
watch.Stop();
time.LastFrameElapsedTime = watch.Elapsed;
time.TotalGameTime = time.TotalGameTime + watch.Elapsed;
});
scene.Dispose();
// TODO ce soir
// frustrum culling pour la planète.
// backface culling pour le ground.
//
}
示例5: Init
public long Init(int objectsCount)
{
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch ();
try
{
watch.Reset ();
watch.Start ();
Random randomizer = new Random ();
data = new int[objectsCount];
for (int i = 0; i < data.Length; i++)
{
data[i] = randomizer.Next () * (-1) * (randomizer.Next () % 2);
}
isInited = true;
watch.Stop ();
dataCopy = (int[])data.Clone ();
Console.WriteLine ("Initialized data ({1} items) in {0} msec.", watch.ElapsedMilliseconds, data.Length);
return watch.ElapsedMilliseconds;
}
catch (Exception ex)
{
isInited = false;
Console.WriteLine ("Unable to initialize data: {0}", ex.Message);
return INIT_FAILED;
}
}
示例6: Main
static void Main(string[] args)
{
TwitchPlays.ChannelName = "fluzzarn";
TwitchPlays.NickName = "Fluzzarn";
TwitchPlays.Password = Password.OAuthPWord;
TwitchPlays.ServerAddress = "irc.twitch.tv";
TwitchPlays.Connect();
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
timer.Start();
kappa k = printKapps;
TwitchPlays.AddCommandToFunction("Kappa",printKapps);
TwitchPlays.AddCommandToFunction("exit", quit);
TwitchPlays.AddCommandToFunction("quit", quit);
while(true)
{
if(timer.ElapsedMilliseconds > 5000)
{
string command = TwitchPlays.GetMostCommonCommand();
int amount = TwitchPlays.GetFrequencyOfCommand(command);
Console.WriteLine("Most common input was: " + command + " with " + amount + " instances");
TwitchPlays.ExecuteCommand(command);
TwitchPlays.ClearCommands();
timer.Reset();
timer.Start();
}
}
}
示例7: Main
static void Main(string[] args)
{
int runLength = 10, FEC = 1000;
//宣告要將結果存入 tsp.txt 檔案裡
TSP ACOtsp = new TSP();
//寫入檔案
StreamWriter sw = new StreamWriter("test.csv");
sw.WriteLine("case, best Value, Average, STD, average time");
//馬錶
System.Diagnostics.Stopwatch swt = new System.Diagnostics.Stopwatch();
//ACObest 最好的值(越小越好);best 十次的值; 平均十次的值(/10); 標準差(best) ;平均時間(time / 10)
double[] best = new double[10];
for (int i = 0; i < ACOtsp.problem.Length; i++)
{
double bestsum = 0.0;
double ACObest = double.MaxValue;
for (int k = 0; k < runLength; k++)
{
swt.Reset();
swt.Start();
ACOtsp.initDistance(i); //問題初始
ACOtsp.fitness=0;
//方法初始化
ACOtsp.Init(40, ACOtsp.distanceLength, 0, ACOtsp.distanceLength - 1/*,
ACOOption.RepeatableOption.Nonrepeatable, ACOOption.CycleOption.Cycle*/);
ACOtsp.Run(FEC);
// Console.WriteLine(ACOtsp.GbestFitness);
best[k] = ACOtsp.GBestFitness;
bestsum += best[k];
if (best[k] < ACObest)
{
ACObest = best[k];
}
//Console.WriteLine("fitness=" + ACOtsp.fitness);
//Console.WriteLine("fitness=" + fitness);
Console.WriteLine("ACObest = " + ACOtsp.GBestFitness);
}
//Console.Read();
swt.Stop();
//碼錶出來的時間是毫秒,要轉成秒,除以1000。
double time = (double)swt.Elapsed.TotalMilliseconds / 1000;
Console.WriteLine(ACOtsp.problem[i] + ", " + ACObest + "," + bestsum / 10 + "," + std(best) + "," + time / 10);
sw.WriteLine(ACOtsp.problem[i] + ", " + ACObest + "," + bestsum / 10 + "," + std(best) + "," + time / 10);
}
sw.Close();
}
示例8: StartTest
public void StartTest(int times)
{
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();//引用stopwatch物件
double avgCostTime = 0;
for (int t = 0; t < times; t++)
{
sw.Reset();
sw.Start();
TO.Optimization();
sw.Stop();
string costTime = sw.Elapsed.TotalMilliseconds.ToString();
avgCostTime += System.Convert.ToDouble(costTime);
List<string> record = TO.GetRecord_GA();
string result = record[record.Count - 1];
results.Add(result);
/*foreach (string re in record)
{
this.dataGridView1.Rows[this.dataGridView1.Rows.Add()].Cells[0].Value = re;
}*/
int row = this.dataGridView1.Rows.Add();
this.dataGridView1.Rows[row].Cells[0].Value = result;
this.dataGridView1.Rows[row].Cells[1].Value = costTime;
}
avgCostTime = Math.Round(avgCostTime /= times, 0, MidpointRounding.AwayFromZero);
int row2 = this.dataGridView1.Rows.Add();
this.dataGridView1.Rows[row2].Cells[0].Value = "Avg";
this.dataGridView1.Rows[row2].Cells[1].Value = avgCostTime;
}
示例9: Start
// 在一个页面流程内部,要使用多个秒表时,用名称以区分
public static void Start( String stopwatchName )
{
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
stopwatch.Reset();
stopwatch.Start();
CurrentRequest.setItem( stopwatchName, stopwatch );
}
示例10: Main
// functions
static void Main(string[] args)
{
if (args.Length < 6 )
{
Console.WriteLine("Error -- not enough parameters");
Console.WriteLine("Usage : DataImporter.exe file[path], ip, port, catalog, id, passwd");
Console.ReadKey();
return;
}
DbManager.SetConnString(string.Format("Data Source={0},{1};Initial Catalog={2};USER ID={3};PASSWORD={4}", args[1], args[2], args[3], args[4], args[5]));
// argument가 directory면 파일을 만들고
string listFileName = "";
System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(args[0]);
if( dirInfo.Exists )
{
listFileName = args[0] + "\\data_table.lst";
System.IO.StreamWriter listWriter = new System.IO.StreamWriter(listFileName);
foreach ( System.IO.FileInfo fileInfo in dirInfo.GetFiles())
{
if(fileInfo.Extension == ".csv" )
{
listWriter.WriteLine(fileInfo.FullName);
}
}
listWriter.Close();
}
else
{
listFileName = args[0];
}
// 시간 측정
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Reset();
sw.Start();
string[] dataFiles = System.IO.File.ReadAllLines(listFileName, Encoding.Default);
if( dataFiles.Length == 0)
{
Console.WriteLine("Error : invalid file or directory.!");
Console.ReadLine();
return;
}
// 파일이면 해당 파일의 리스트를 읽어서 사용한다.
System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
FileManager.Init(string.Format("{0}\\{1}.log", System.IO.Directory.GetCurrentDirectory(), currentProcess.ProcessName));
Parallel.For(0, dataFiles.Length, (i) =>
{
FileManager fileManager = new FileManager();
fileManager.ImportToDb(dataFiles[i]);
});
FileManager.Release();
sw.Stop();
Console.WriteLine("수행시간 : {0}", sw.ElapsedMilliseconds / 1000.0f);
Console.ReadLine();
}
示例11: Page_Load
protected void Page_Load( object sender, EventArgs e )
{
var url = ConfigurationManager.AppSettings.Get( "CLOUDANT_URL" );
var connection = new Connection( new Uri( url ) );
if ( !connection.ListDatabases().Contains( "gmkreports" ) )
{
connection.CreateDatabase( "gmkreports" );
}
var repository = new Repository<Report>( connection.CreateSession( "gmkreports" ) );
var report = new Report { ID = Guid.NewGuid(), Type = 1, AccessionNumber = "123", Contents = "abcd" };
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
watch.Reset();
watch.Start();
var id = repository.Save( report ).Id;
var retrievedReport = repository.Get( id );
watch.Stop();
if ( retrievedReport.ID == report.ID && retrievedReport.Type == report.Type && retrievedReport.AccessionNumber == report.AccessionNumber && retrievedReport.Contents == report.Contents )
{
_label.Text = watch.ElapsedMilliseconds.ToString();
}
else
{
_label.Text = "Error";
}
}
示例12: _watch
private void _watch(int time, bool reset = true, bool forceGC = false, string tag = "")
{
if (WatchEvent == null) return;
List<WatchFunction> _eventList = new List<WatchFunction>();
foreach (WatchFunction _delegateItem in WatchEvent.GetInvocationList()) {
_eventList.Add(_delegateItem);
}
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
StringBuilder _sb = new StringBuilder();
for (int j = 0; j < _eventList.Count; j++) {
WatchFunction _watchItem = _eventList[j];
long _memory = System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64;
sw.Start();
for (int k = 0; k < time; k++) {
_watchItem();
}
sw.Stop();
_memory = System.Diagnostics.Process.GetCurrentProcess().PrivateMemorySize64 - _memory;
Console.WriteLine(string.Format("{0,20}: {1,10} (spend: {2,10}, Memory: {3,10})", tag + _watchItem.Method.Name, sw.ElapsedTicks, sw.ElapsedMilliseconds + "ms", _memory / 1024 + "kb"));
if (reset) sw.Reset();
}
Console.WriteLine();
if (forceGC) {
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
}
}
示例13: KeyDown_Enter
private void KeyDown_Enter(RichTextBox rtb)
{
string cmd = getCurLine(rtb);
if (cmd.Length == 0 || cmd == "\n") {
rtb.Text += "\n" + getPrompt();
Scroll2Last(rtb);
return;
}
int err = 0;
string errmsg;
#if false
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Reset(); sw.Start();
#endif
err = myViewer.mruby_exec(cmd, out errmsg);
#if false
sw.Stop();
string result = "Time:" + sw.Elapsed.ToString() + "\n";
#else
string result = "";
#endif
if (!myViewer.mruby_isCodeBlockOpen()) {
if (err == 0) {
result += myViewer.mruby_p();
}
else {
result += errmsg + "\n";
}
}
rtb.Text += "\n" + result + getPrompt();
//rtb.Select(rtb.TextLength - getPrompt().Length, getPrompt().Length);
//rtb.SelectionColor = Color.LightGreen;
}
示例14: Main
static void Main(string[] args)
{
//耗時計算
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Reset();
sw.Start();
Console.WriteLine("紀錄位置:"+config.logpath);
//讀取輸入的資料
Readinput();
//多執行續啟動 設定執行緒續數量
ThreadPool.SetMinThreads(config.maxThread, config.maxThread);
foreach (string item in config.getList())
{
//Console.WriteLine(item);
ThreadPool.QueueUserWorkItem(new WaitCallback(checkPing), item);
}
while (true)
{
if (config.listlen() == backcount)
{
Console.WriteLine("done!");
Console.WriteLine("執行了{0}次", backcount.ToString());
Console.WriteLine("重試了{0}次", retrytimes.ToString());
Console.WriteLine("回應數量:{0}", existcount.ToString());
break;
}
Thread.Sleep(300);
}
sw.Stop();
Console.WriteLine("耗時:{0} ms",((int)sw.Elapsed.TotalMilliseconds).ToString());
Console.WriteLine("按下任意鍵結束...");
Console.ReadKey();
}
示例15: WorkerEvents
static private void WorkerEvents()
{
Tuple<EventDelegate, Effect, Effect> cEvent;
System.Diagnostics.Stopwatch cWatch = new System.Diagnostics.Stopwatch();
while (true)
{
try
{
cEvent = _aqEvents.Dequeue();
cWatch.Reset();
cWatch.Restart();
cEvent.Item1(cEvent.Item2, cEvent.Item3);
(new Logger()).WriteDebug3("event sended [hc = " + cEvent.Item3.GetHashCode() + "][" + cEvent.Item1.Method.Name + "]");
cWatch.Stop();
if (40 < cWatch.ElapsedMilliseconds)
(new Logger()).WriteDebug3("duration: " + cWatch.ElapsedMilliseconds + " queue: " + _aqEvents.nCount);
if (0 < _aqEvents.nCount)
(new Logger()).WriteDebug3(" queue: " + _aqEvents.nCount);
}
catch (System.Threading.ThreadAbortException)
{
break;
}
catch (Exception ex)
{
(new Logger()).WriteError(ex);
}
}
}