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


C# Stopwatch.ToString方法代码示例

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


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

示例1: StopwatchToString_NullFormatString_NameDefaultsToStopwatch

 public void StopwatchToString_NullFormatString_NameDefaultsToStopwatch()
 {
     Stopwatch testStopwatch = new Stopwatch();
     Assert.AreEqual(
         "Stopwatch completed in 0ms.",
         testStopwatch.ToString(null),
         "Where a null format string is provided for the stopwatch name, the name should default to 'Stopwatch'.");
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:8,代码来源:DebuggingExtensionsTests.cs

示例2: StopwatchToString_FormatStringWithNoParameters_StopwatchReferreredToUsingFormatString

 public void StopwatchToString_FormatStringWithNoParameters_StopwatchReferreredToUsingFormatString()
 {
     String value = Random.RandomString();
     Stopwatch testStopwatch = new Stopwatch();
     Assert.AreEqual(
         String.Format("{0} completed in 0ms.", value),
         testStopwatch.ToString(value),
         "Where a format string without additional parameters is provided, this is used for the stopwatch name.");
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:9,代码来源:DebuggingExtensionsTests.cs

示例3: TakeAction

        public void TakeAction(string i_MachineName, string i_IP, string i_ServiceName,string i_DisplayName, eOperationType i_OperationType)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            LogManager.Instance.WriteInfo("Action " + Enum.GetName(typeof(eOperationType), i_OperationType) + "on all agents started ");
            m_AgentsManager.TakeAction(i_MachineName, i_IP, i_ServiceName, i_DisplayName, i_OperationType);
            sw.Stop();
            LogManager.Instance.WriteInfo("Action " + Enum.GetName(typeof(eOperationType), i_OperationType) + "on all agents ended, took: "+sw.ToString());

        }
开发者ID:ddotan,项目名称:Service.Restarter.Agent,代码行数:10,代码来源:DashboardManager.cs

示例4: StopwatchToString_FormatStringWithParameters_StopwatchReferreredToUsingFormattedString

 public void StopwatchToString_FormatStringWithParameters_StopwatchReferreredToUsingFormattedString()
 {
     String value1 = Random.RandomString();
     String value2 = Random.RandomString();
     String value3 = Random.RandomString();
     Stopwatch testStopwatch = new Stopwatch();
     Assert.AreEqual(
         String.Format("{0} test {2} {1} completed in 0ms.", value1, value2, value3),
         testStopwatch.ToString("{0} test {2} {1}", value1, value2, value3),
         "Where a format string with parameters is provided, this is formatted and used for the stopwatch name.");
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:11,代码来源:DebuggingExtensionsTests.cs

示例5: StopwatchToString_WithTimeElapsed_ContainsTimeElapsed

 public void StopwatchToString_WithTimeElapsed_ContainsTimeElapsed()
 {
     Stopwatch testStopwatch = new Stopwatch();
     testStopwatch.Start();
     Thread.Sleep(Random.Next(1, 5));
     testStopwatch.Stop();
     Assert.AreEqual(
         testStopwatch.ElapsedMilliseconds,
         int.Parse(
             Regex.Match(testStopwatch.ToString(null), "completed in ([0-9]+).?[0-9]*ms.", RegexOptions.None)
                 .Groups[1]
                 .ToString()),
         "The number of milliseconds elapsed should be stated in the ToString result.");
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:14,代码来源:DebuggingExtensionsTests.cs

示例6: TestPerformance

 public void TestPerformance()
 {
     ContextStack<int> contextStack = new ContextStack<int>();
     Stopwatch s = new Stopwatch();
     s.Start();
     Parallel.For(0, Loops, i =>
                                {
                                    using (contextStack.Region(i))
                                    {
                                        Assert.AreEqual(i, contextStack.Current);
                                    }
                                });
     s.Stop();
     Trace.WriteLine(s.ToString("{0} loops", Loops));
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:15,代码来源:TestContextStack.cs

示例7: Stopwatch_ToString_ReturnsCorrectFormat

 public void Stopwatch_ToString_ReturnsCorrectFormat()
 {
     Stopwatch s = new Stopwatch();
     Random random = Tester.RandomGenerator;
     s.Start();
     Thread.Sleep(random.Next(0, 1000));
     s.Stop();
     string randomString = random.RandomString();
     Assert.AreEqual(
         String.Format(
             "Test stopwatch {0} completed in {1}ms.",
             randomString,
             (s.ElapsedTicks * 1000M) / Stopwatch.Frequency),
         s.ToString("Test stopwatch {0}", randomString));
 }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:15,代码来源:TestExtensionsTests.cs

示例8: ReverseArray

		public static int ReverseArray(Stock[] input)
		{
			int counter = 0;
			Stopwatch time = new Stopwatch();
			time.Start();
			/*for (int i = 0; i < (input.Length - 1) / 2; i++)
			{
				Stock temp = input[i];
				input[i] = input[(input.Length - 1) - i];
				input[(input.Length - 1) - i] = temp;
				counter++;
			} 
			Debug.WriteLine(time.ToString());*/

			Parallel.For(0, (input.Length - 1) / 2, i => {
				Stock temp = input[i];
				input[i] = input[(input.Length - 1) - i];
				input[(input.Length - 1) - i] = temp;
				counter++;
			});
			
			Debug.WriteLine(time.ToString());

			return counter;
		}
开发者ID:adamlinscott,项目名称:CMP1124M-Algorithms-and-Complexity,代码行数:25,代码来源:Algorithms.cs

示例9: TestWeakConcurrentDictionaryReferences

        public void TestWeakConcurrentDictionaryReferences()
        {
            const int elements = 100000;
            Random random = new Random();
            WeakConcurrentDictionary<int, TestClass> weakConcurrentDictionary =
                new WeakConcurrentDictionary<int, TestClass>(allowResurrection: false);
            ConcurrentDictionary<int, TestClass> referenceDictionary = new ConcurrentDictionary<int, TestClass>();
            int nullCount = 0;
            int unreferencedNullCount = 0;
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            Parallel.For(
                0,
                elements,
                l =>
                {
                    // Include nulls ~25% of the time.
                    TestClass t;
                    if (random.Next(4) < 3)
                        t = new TestClass(random.Next(int.MinValue, int.MaxValue));
                    else
                    {
                        t = null;
                        Interlocked.Increment(ref nullCount);
                    }

                    weakConcurrentDictionary.Add(l, t);

                    // Only keep references ~33% of the time.
                    if (random.Next(3) == 0)
                        referenceDictionary.AddOrUpdate(l, t, (k, v) => t);
                    else if (t == null)
                        Interlocked.Increment(ref unreferencedNullCount);
                });
            stopwatch.Stop();
            Trace.WriteLine(stopwatch.ToString("Populating dictionaries with {0} elements", elements));

            //GC.WaitForFullGCComplete(5000);
            stopwatch.Restart();
            long bytes = GC.GetTotalMemory(true);
            stopwatch.Stop();
            Trace.WriteLine(stopwatch.ToString("Garbage collection"));
            Trace.WriteLine($"Memory: {bytes / 1024}K");

            // Check that we have l
            Assert.IsTrue(referenceDictionary.Count <= elements);

            int refCount = referenceDictionary.Count;

            stopwatch.Restart();
            int weakCount = weakConcurrentDictionary.Count;
            stopwatch.Stop();
            Trace.WriteLine(stopwatch.ToString("Counting '{0}' elements", weakCount));

            stopwatch.Restart();
            weakCount = weakConcurrentDictionary.Count;
            stopwatch.Stop();
            Trace.WriteLine(stopwatch.ToString("Counting '{0}' elements again", weakCount));

            int floor = refCount + unreferencedNullCount;

            Trace.WriteLine(
                string.Format(
                    "Referenced Dictionary Count: {1}{0}Weak Dictionary Count: {2}{0}Null values: {3} (unreferenced: {4}){0}Garbage Collected: {5}{0}Pending Collection: {6}{0}",
                    Environment.NewLine,
                    refCount,
                    weakCount,
                    nullCount,
                    unreferencedNullCount,
                    elements - weakCount,
                    weakCount - floor
                    ));

            // Check we only have references to referenced elements.
            Assert.AreEqual(refCount + unreferencedNullCount, weakCount);

            // Check everything that's still referenced is available.
            stopwatch.Restart();
            Parallel.ForEach(
                referenceDictionary,
                kvp =>
                {
                    TestClass value;
                    Assert.IsTrue(weakConcurrentDictionary.TryGetValue(kvp.Key, out value));
                    Assert.AreEqual(kvp.Value, value);
                });
            stopwatch.Stop();
            Trace.WriteLine(stopwatch.ToString("Checking '{0}' elements", weakCount));
        }
开发者ID:webappsuk,项目名称:CoreLibraries,代码行数:89,代码来源:TestWeak.cs

示例10: Application

        public Application(IApp page)
        {
            __that = this;

            this.yield = message =>
            {
                Native.window.alert("hello! " + new { message });
            };


            //((IHTMLElement)Native.document.body.parentNode).style.borderTop = "1em yellow yellow";

            //IStyleSheet.Default["html"].style.borderTop = "1em yellow yellow";


            IStyleSheet.Default["body"].style.borderLeft = "0em yellow solid";

            // activate all animations?
            IStyleSheet.Default["body"].style.transition = "border-left 300ms linear";
            IStyleSheet.Default["body"].style.borderLeft = "3em yellow solid";

            new IHTMLDiv
            {
                innerHTML = @"
<style>
html {
    transition: border-top 500ms linear;
    border-top: 4em solid cyan;
}

</style>"
            }.With(
           async div =>
           {
               //await Native.window.requestAnimationFrameAsync;

               // wont work for html?
               await Task.Delay(100);

               div.AttachToDocument();
           }
       );

            #region proof we can still find our element by id even if on a sub page
            new IHTMLTextArea { }.AttachTo(Native.document.body.parentNode).With(
                async area =>
                {
                    area.style.position = IStyle.PositionEnum.absolute;
                    area.style.right = "1em";
                    area.style.bottom = "1em";
                    area.style.zIndex = 1000;
                    area.readOnly = true;


                    Action colors = async delegate
                    {
                        for (int i = 0; i < 3; i++)
                        {

                            area.style.backgroundColor = "red";
                            await Task.Delay(200);
                            area.style.backgroundColor = "yellow";
                            await Task.Delay(200);
                        }
                        await Native.window.requestAnimationFrameAsync;
                        area.style.transition = "background-color 10000ms linear";

                        await Native.window.requestAnimationFrameAsync;

                        area.style.backgroundColor = "white";
                    };


                    colors();




                    var st = new Stopwatch();
                    st.Start();

                    while (true)
                    {
                        // proof we can still find our element by id even if on a sub page
                        area.value = page.message.innerText + "\n" + st.ToString();

                        await Task.Delay(500);
                    }
                }
            );
            #endregion





            //page.Location = Native.document.location.hash;

            // #/OtherPage.htm

//.........这里部分代码省略.........
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:101,代码来源:Application.cs


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