public void TimeActionTest2()
        {
            var elapsed = StopwatchHelpers.TimeAction(() =>
                                                      { for (int i = 0; i < Math.Pow(2, 18); i++)
                                                        {
                                                            ;
                                                        }
                                                      });

            Assert.NotEqual(0, elapsed);
        }
 public void TimeActionTest3()
 {
     for (int i = 0; i < 10; ++i)
     {
         Assert.NotEqual(0, StopwatchHelpers.TimeAction(i, j =>
                                                        { for (int k = 0; k < Math.Pow(2, j + 16); ++k)
                                                          {
                                                              ;
                                                          }
                                                        }));
     }
 }
        public async Task TimeActionTest()
        {
            var result = await StopwatchHelpers.TimeAction <object, object>(null, async value =>
            {
                await RandomDelay(15, 150);
                return(value);
            },
                                                                            elapsed =>
            {
                _log.WriteLine($"{elapsed} ms");
            });

            Assert.Null(result);
        }
        public void TimeActionTest1()
        {
            var result = false;

            StopwatchHelpers.TimeAction(() =>
            {
                _log.WriteLine("Action called.");
            },
                                        elapsed =>
            {
                _log.WriteLine($"{elapsed} ms");
                result = true;
            });

            Assert.True(result);
        }
示例#5
0
        public void ComputesCorrectTimespan()
        {
            var sw = Stopwatch.StartNew();

            Thread.Sleep(50);

            sw.Stop();

            // Extract the internal ticks
            var stopwatchTicks = (long)typeof(Stopwatch)
                                 .GetMethod("GetRawElapsedTicks", BindingFlags.Instance | BindingFlags.NonPublic)
                                 .Invoke(sw, null);

            var elapsed = StopwatchHelpers.GetElapsed(stopwatchTicks);

            Assert.Equal(sw.Elapsed, elapsed);
        }
        public void TimeActionComplexTest()
        {
            var result = false;
            var values = new[] { "1", "2", "three", "4", "5", "six" };

            foreach (var value in values)
            {
                StopwatchHelpers.TimeAction <string>(value,
                                                     val =>
                {
                    int v;
                    if (Int32.TryParse(val, out v))
                    {
                        for (int i = 0; i < v * 1024; ++i)
                        {
                            if (i % 128 == 0)
                            {
                                System.Diagnostics.Debug.Write($".");
                                Thread.Sleep(10);
                            }
                        }
                    }
                    else
                    {
                        System.Diagnostics.Debug.Write($". {val} ");
                    }
                },
                                                     elapsed =>
                {
                    result |= true;
                    _log.WriteLine($". [{elapsed} ms]");
                });
            }

            Assert.True(result);
        }