当前位置: 首页>>代码示例>>C#>>正文


C# System.Diagnostics.Stopwatch.Start方法代码示例

本文整理汇总了C#中System.Diagnostics.Stopwatch.Start方法的典型用法代码示例。如果您正苦于以下问题:C# System.Diagnostics.Stopwatch.Start方法的具体用法?C# System.Diagnostics.Stopwatch.Start怎么用?C# System.Diagnostics.Stopwatch.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Diagnostics.Stopwatch的用法示例。


在下文中一共展示了System.Diagnostics.Stopwatch.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            var ControllerIPAddress = new IPAddress(new byte[] { 192, 168, 0, 2 });
            var ControllerPort = 40001;
            var ControllerEndPoint = new IPEndPoint(ControllerIPAddress, ControllerPort);
            _client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            var header = "@";
            var command = "00C";
            var checksum = "E3";
            var end = "\r\n";
            var data = header + command + checksum + end;
            byte[] bytes = new byte[1024];

            //Start Connect
            _connectDone.Reset();
            watch.Start();
            _client.BeginConnect(ControllerIPAddress, ControllerPort, new AsyncCallback(ConnectCallback), _client);
            //wait 2s
            _connectDone.WaitOne(2000, false);

            var text = (_client.Connected) ? "ok" : "ng";
            richTextBox1.AppendText(text + "\r\n");
            watch.Stop();
            richTextBox1.AppendText("Consumer time: " + watch.ElapsedMilliseconds + "\r\n");
        }
开发者ID:Joncash,项目名称:HanboAOMClassLibrary,代码行数:27,代码来源:AsyncConnectionForm.cs

示例2: btnVector_Click

        /// <summary>
        /// Tests for Vektor class
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnVector_Click(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();
            txtVector.Text = "Starting test suite for the Vektor class.\r\n\r\n";

            // Sample data
            List<Eksam.Vektor> vectors = new List<Vektor>{
                new Vektor(),
                new Vektor(1,1),
                new Vektor(0,1),
                new Vektor(2.2, 1.2),
                new Vektor(10,-4),
                null
            };

            // Go over all defined operations and input combinations
            foreach (Vektor vector in vectors)
            {
                foreach (Vektor secondVector in vectors)
                {
                    txtVector.Text += vector + " + " + secondVector + " = " + (vector + secondVector) + "\r\n";
                    txtVector.Text += vector + " - " + secondVector + " = " + (vector - secondVector) + "\r\n";
                    txtVector.Text += vector + " == " + secondVector + " ... " + (vector == secondVector) + "\r\n";
                    txtVector.Text += vector + vector + " (length " + (vector == null ? 0 : vector.Length()) + ") > " + secondVector + " (length " + (secondVector == null ? 0 : secondVector.Length()) + ")" + " ... " + (vector > secondVector) + "\r\n";
                    txtVector.Text += vector + vector + " (length " + (vector == null ? 0 : vector.Length()) + ") < " + secondVector + " (length " + (secondVector == null ? 0 : secondVector.Length()) + ")" + " ... " + (vector < secondVector) + "\r\n";
                }
            }

            watch.Stop();
            double elapsed = watch.ElapsedMilliseconds;
            txtVector.Text += "\r\nTest suite finished, time elapsed: " + elapsed + "ms.";
        }
开发者ID:anroots,项目名称:ITK-projects,代码行数:38,代码来源:MainWindow.xaml.cs

示例3: 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);
        }
开发者ID:kijanawoodard,项目名称:EventStore,代码行数:30,代码来源:Stopwatch.cs

示例4: 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();
        }
开发者ID:cucmberium,项目名称:Fairytale,代码行数:34,代码来源:Program.cs

示例5: button2_Click

        private void button2_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            label3.Text = "???ms";
            label4.Text = "Total is ";
            richTextBox1.Text = "";
            sw.Reset();
            sw.Start();
            List<int> resultList = primeNumbers.LinearSieve((int)numericUpDown1.Value, (int)numericUpDown2.Value);
            sw.Stop();
            label3.Text = (sw.Elapsed.TotalMilliseconds.ToString() + " ms").ToString();
            label4.Text = "Total is " + resultList.Count;
            sw.Start();

            string a = string.Join(",", resultList.ToArray());
                //sw.Stop();
                //Console.WriteLine((sw.Elapsed.TotalMilliseconds.ToString() + " ms").ToString());
                richTextBox1.Invoke((MethodInvoker)delegate {
                    //sw.Reset();
                    //sw.Start();
                    richTextBox1.AppendText(a);
                    sw.Stop();
                    label3.Text = label3.Text + "/" + (sw.Elapsed.TotalMilliseconds.ToString() + " ms").ToString();
                }
            );
        }
开发者ID:spyteric,项目名称:AlgorChallenge1,代码行数:26,代码来源:Form1.cs

示例6: TestExecuteIntersectionQuery

        public void TestExecuteIntersectionQuery()
        {
            NUnit.Framework.Assert.IsTrue(System.IO.File.Exists(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp")),
                                          "Specified shapefile is not present!");

            var shp = new SharpMap.Data.Providers.ShapeFile(GetTestDataFilePath("SPATIAL_F_SKARVMUFF.shp"), false, false);
            shp.Open();

            var fds = new SharpMap.Data.FeatureDataSet();
            var bbox = shp.GetExtents();
            //narrow it down
            bbox.ExpandBy(-0.425*bbox.Width, -0.425*bbox.Height);

            //Just to avoid that initial query does not impose performance penalty
            shp.DoTrueIntersectionQuery = false;
            shp.ExecuteIntersectionQuery(bbox, fds);
            fds.Tables.RemoveAt(0);

            //Perform query once more
            var sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            shp.ExecuteIntersectionQuery(bbox, fds);
            sw.Stop();
            System.Console.WriteLine("Queried using just envelopes:\n" + fds.Tables[0].Rows.Count + " in " +
                                     sw.ElapsedMilliseconds + "ms.");
            fds.Tables.RemoveAt(0);

            shp.DoTrueIntersectionQuery = true;
            sw.Reset();
            sw.Start();
            shp.ExecuteIntersectionQuery(bbox, fds);
            sw.Stop();
            System.Console.WriteLine("Queried using prepared geometries:\n" + fds.Tables[0].Rows.Count + " in " +
                                     sw.ElapsedMilliseconds + "ms.");
        }
开发者ID:PedroMaitan,项目名称:sharpmap,代码行数:35,代码来源:ShapeFileProviderTests.cs

示例7: TestFromTxtFile

        public void TestFromTxtFile(string file)
        {
            var wordUtil = new WordDict();
            var expectWordCount = 0;
            using (var sr = new StreamReader(file, Encoding.UTF8))
            {
                string line = null;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line == string.Empty) continue;
                    wordUtil.Add(line);
                    expectWordCount++;
                }
            }

            var watcher = new System.Diagnostics.Stopwatch();
            watcher.Start();
            var ms = new MemoryStream();
            wordUtil.SaveTo(ms);
            watcher.Stop();

            Console.WriteLine("build dawg elapsed time:" + watcher.Elapsed.TotalMilliseconds + "'ms");

            watcher.Reset();
            watcher.Start();
            ms.Position = 0;
            wordUtil = WordDict.LoadFrom(ms);
            watcher.Stop();
            Console.WriteLine("load dawg file elapsed time:" + watcher.Elapsed.TotalMilliseconds + "'ms");
            Assert.AreEqual(expectWordCount, wordUtil.Count);
        }
开发者ID:xiaopohou,项目名称:CWSharp,代码行数:31,代码来源:WordUtilTests.cs

示例8: 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();
                }


            }
        }
开发者ID:Fluzzarn,项目名称:TwitchPlaysYourGame,代码行数:33,代码来源:Program.cs

示例9: 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.
            //
        }
开发者ID:crissian,项目名称:planets,代码行数:29,代码来源:Program.cs

示例10: Main

        public static void Main(string[] args)
        {
            Director.Initialize ();
            Director.Instance.GL.Context.SetClearColor(255,255,255,0);

            walker = new Walker("run.png", "run.xml");

            var scene = new Scene();
            scene.Camera.SetViewFromViewport();
            SpriteTile sprite = walker.Get("walkLeft00");

            sprite.Position = scene.Camera.CalcBounds().Center;
            sprite.CenterSprite();
            sprite.Scale = new Vector2(1,1);
            scene.AddChild(sprite);

            Director.Instance.RunWithScene(scene, true);

            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();

            int spriteOffset = 0;
            timer.Start();
            bool walkLeft = true;
            while(true) {
                if(timer.ElapsedMilliseconds > 25f) {
                    string spriteName;
                    if(walkLeft) {
                        spriteName = "walkLeft";
                        sprite.Position = new Vector2(sprite.Position.X - 10, sprite.Position.Y);
                    } else {
                        spriteName = "walkRight";
                        sprite.Position = new Vector2(sprite.Position.X + 10, sprite.Position.Y);
                    }
                    if(sprite.Position.X < 0) {
                        walkLeft = false;
                    }
                    if(sprite.Position.X > Director.Instance.GL.Context.GetViewport().Width) {
                        walkLeft = true;
                    }
                    spriteName += spriteOffset.ToString("00");

                    sprite.TileIndex2D = walker.Get(spriteName).TileIndex2D;

                    if(spriteOffset >= 8) {
                        spriteOffset = 0;
                    } else {
                        spriteOffset ++;
                    }

                    timer.Reset();
                    timer.Start();
                }

                Director.Instance.Update();
                Director.Instance.Render();
                Director.Instance.GL.Context.SwapBuffers();
                Director.Instance.PostSwap();
            }
        }
开发者ID:kevadsett,项目名称:SpriteWalker,代码行数:59,代码来源:AppMain.cs

示例11: Time

		private long Time(Action toDo, int repetitions)
		{
			var stopwatch = new System.Diagnostics.Stopwatch();
			stopwatch.Start();
			{
				stopwatch.Start();
				for (int i = 0; i < repetitions; i ++)
				{
					toDo();
				}
			}
			stopwatch.Stop();
			return stopwatch.ElapsedTicks;
		}
开发者ID:antonydenyer,项目名称:ProgrammingKatas,代码行数:14,代码来源:PalindromicTests.cs

示例12: TestWarpedLineSymbolizer

        public void TestWarpedLineSymbolizer()
        {
            var p = new SharpMap.Data.Providers.ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false);

            var l = new SharpMap.Layers.VectorLayer("roads", p);
            var cls = new SharpMap.Rendering.Symbolizer.CachedLineSymbolizer();
            cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Gold, 2) });
            cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander { Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetGreaterSeries(3, 3), Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1) });
            l.Style.LineSymbolizer = cls;

            var m = new SharpMap.Map(new System.Drawing.Size(720, 540)) {BackColor = System.Drawing.Color.Cornsilk};
            m.Layers.Add(l);

            m.ZoomToExtents();

            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            var bmp = m.GetMap();
            sw.Stop();
            System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads1.bmp");

            cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander
            {
                Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetTriangleSeries(4, 7),
                Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1),
                Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick)
            };
            sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads2.bmp");

            //cls.LineSymbolizeHandlers[0] = cls.LineSymbolizeHandlers[1];
            cls.LineSymbolizeHandlers[1] = new SharpMap.Rendering.Symbolizer.WarpedLineSymbolizeHander
                                               {
                                                   Pattern = SharpMap.Rendering.Symbolizer.WarpedLineSymbolizer.GetZigZag(4, 4),
                                                   Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 1),
                                                   //Fill = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick)
                                               };
            sw.Start();
            bmp = m.GetMap();
            sw.Stop();
            System.Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
            bmp.Save("AurichRoads3.bmp");

        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:49,代码来源:LineSymbolizerTest.cs

示例13: Block

		static Block ()
		{
#if !MF_FRAMEWORK_VERSION_V4_3
			sw = new System.Diagnostics.Stopwatch ();
			sw.Start ();
#endif
		}
开发者ID:Roddoric,项目名称:Monkey.Robotics,代码行数:7,代码来源:Block.cs

示例14: Performance

		//[TestMethod]
		public void Performance()
		{
			var sw = new System.Diagnostics.Stopwatch();
			sw.Start();
			for (var i = 0; i < 200; i++) this.DefinedIPlugin();
			Assert.IsTrue(sw.ElapsedMilliseconds < 2000);
		}
开发者ID:NatLee,项目名称:KanColleViewer,代码行数:8,代码来源:RequireIPluginTest.cs

示例15: InterOpSpeed

 public void InterOpSpeed()
 {
     const int TESTSIZE = 100;
     count = 0;
     // get some random prices
     Tick[] data = RandomTicks.GenerateSymbol(sym, TESTSIZE);
     // track the time
     System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
     int bad = 0;
     sw.Start();
     for (int i = 0; i < data.Length; i++)
     {
         int err = SendOrder(sym, true, 300, (double)data[i].trade, 0, 1, "TESTACCOUNT", "TESTDEST");
         if (err!=0) bad++;
     }
     sw.Stop();
     long elapms = sw.ElapsedMilliseconds;
     double elap = (double)elapms/1000;
     double rate = TESTSIZE / elap;
     Console.WriteLine("InterOpSpeed elap: " + elap.ToString("N1") + " rate: " + rate.ToString("N0") + " orders/sec");
     // make sure orders received
     Assert.AreEqual(data.Length, count);
     // make sure no bad orders
     Assert.AreEqual(0,bad);
     // make sure fast
     Assert.LessOrEqual(elap, .5);
 }
开发者ID:antonywu,项目名称:tradelink,代码行数:27,代码来源:TestTLFastInterop.cs


注:本文中的System.Diagnostics.Stopwatch.Start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。