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


C# Stopwatch.Start方法代码示例

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


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

示例1: Get

        /// <summary>
        /// Verify if the user credentials are valid
        /// </summary>
        /// <param name="username">MAL Username</param>
        /// <param name="password">MAL Password</param>
        /// <returns></returns>
        public async Task<HttpResponseMessage> Get([FromUri] string username, [FromUri] string password)
        {
            var stopWatch = new Stopwatch();
            stopWatch.Start();
            Log.Information("Received credential verification request for {username}", username);
            bool result;
            try
            {
                result = await _credentialVerification.VerifyCredentials(username, password);
            }
            catch (UnauthorizedAccessException)
            {
                Log.Information("Received unauthorized - Credentials for {username} isn't valid", username);
                result = false;
            }
            catch (Exception ex)
            {
                Log.Error(ex, "An error occured while trying to validate user credentails");
                result = false;
            }

            var response = Request.CreateResponse(HttpStatusCode.OK);
            response.Content = new StringContent($"Valid Credetials: {result}");
            stopWatch.Start();
            Log.Information("Verification completed for {username}. Processing took {duration}", username, stopWatch.Elapsed);

            return response;
        }
开发者ID:NinetailLabs,项目名称:MAL.Net---A-.net-API-for-MAL,代码行数:34,代码来源:AuthenticationController.cs

示例2: Main

    public static void Main()
    {
        Stopwatch watch = new Stopwatch();
        Random rand = new Random();
        watch.Start();
        for (int i = 0; i < iterations; i++)
            DayOfYear1(rand.Next(1, 13), rand.Next(1, 29));
        watch.Stop();
        Console.WriteLine("Local array: " + watch.Elapsed);
        watch.Reset();
        watch.Start();
        for (int i = 0; i < iterations; i++)
            DayOfYear2(rand.Next(1, 13), rand.Next(1, 29));
        watch.Stop();
        Console.WriteLine("Static array: " + watch.Elapsed);

        // trying to modify static int []
        daysCumulativeDays[0] = 18;
        foreach (int days in daysCumulativeDays)
        {
            Console.Write("{0}, ", days);
        }
        Console.WriteLine("");

        // MY_STR_CONST = "NOT CONST";
    }
开发者ID:joonhwan,项目名称:study,代码行数:26,代码来源:TestArrayInitialize.cs

示例3: btnInterpretate_Click

        private void btnInterpretate_Click(object sender, EventArgs e)
        {
            try
            {

                Stopwatch timer = new Stopwatch();
                RegularExpression r;

                timer.Reset();
                timer.Start();
                r = new RegularExpression(txtRegEx.Text);
                timer.Stop();
                ReportResult("Parsing '" + txtRegEx.Text + "'", "SUCCESS", r.IsCompiled, timer);

                timer.Reset();
                timer.Start();
                bool result = r.IsMatch(txtInput.Text);
                timer.Stop();
                ReportResult("Matching '" + txtInput.Text + "'", result.ToString(), r.IsCompiled, timer);

                ReportData("Original Expression:\t" + r.OriginalExpression + "\r\nInfix Expression:\t" + r.FormattedExpression + "\r\nPostfix string:\t" + r.PostfixExpression + "\r\n\r\nNon Deterministic Automata has\t\t" + r.NDStateCount + " states.\r\nDeterministic Automata has\t\t" + r.DStateCount + " states.\r\nOptimized Deterministic Automata has\t" + r.OptimizedDStateCount + " states.");

                automataViewer1.Initialize(r);
            }
            catch (RegularExpressionParser.RegularExpressionParserException exc)
            {
                ReportError("PARSER ERROR", exc.ToString());
            }
            catch (Exception exc)
            {
                ReportError("EXCEPTION", exc.ToString());
            }
        }
开发者ID:nzldvd90,项目名称:MidTermAP,代码行数:33,代码来源:Form1.cs

示例4: Form1_Load

 private void Form1_Load(object sender, EventArgs e)
 {
     asdassd.Add("MenuGetir", () => new MyClass());
     Stopwatch sw = new Stopwatch();
     sw.Start();
     for (int i = 0; i < 1000000; i++)
     {
         MyClass c = new MyClass();
     }
     sw.Stop();
     MessageBox.Show(sw.ElapsedMilliseconds.ToString());
     sw.Reset();
     Type t = typeof(MyClass);
     sw.Start();
     for (int i = 0; i < 1000000; i++)
     {
         var c = System.Activator.CreateInstance(Type.GetType(t.FullName));
     }
     sw.Stop();
     MessageBox.Show(sw.ElapsedMilliseconds.ToString());
     sw.Reset();
     sw.Start();
     for (int i = 0; i < 1000000; i++)
     {
         var c = asdassd["MenuGetir"]();
     }
     sw.Stop();
     MessageBox.Show(sw.ElapsedMilliseconds.ToString());
 }
开发者ID:rwx7540,项目名称:inanyalcin,代码行数:29,代码来源:Form1.cs

示例5: Main

        internal static void Main()
        {
            var stopwatch = new Stopwatch();
            var context = new TelerikAcademyEntities();
            stopwatch.Start();
            var employees = context.Employees;
            foreach (var employee in employees)
            {
                Console.WriteLine(
                    "{0}, {1}, {2}",
                    (employee.FirstName + ' ' + employee.LastName).PadLeft(30),
                    employee.Department.Name.PadLeft(30),
                    employee.Address.Town.Name.PadLeft(15));
            }

            stopwatch.Stop();
            Console.WriteLine("Time elapsed: {0} seconds", (decimal)stopwatch.Elapsed.Milliseconds / 1000);

            stopwatch.Reset();
            stopwatch.Start();
            var includeEmployees = context.Employees.Include("Address").Include("Department");
            foreach (var employee in includeEmployees)
            {
                Console.WriteLine(
                    "{0}, {1}, {2}",
                    (employee.FirstName + ' ' + employee.LastName).PadLeft(30),
                    employee.Department.Name.PadLeft(30),
                    employee.Address.Town.Name.PadLeft(15));
            }

            stopwatch.Stop();
            Console.WriteLine("Time elapsed: {0} seconds", (decimal)stopwatch.Elapsed.Milliseconds / 1000);
        }
开发者ID:kalinalazarova1,项目名称:TelerikAcademy,代码行数:33,代码来源:IncludePerfomance.cs

示例6: IterativeDeepening

        // runs an iterative deepening minimax search limited by the given timeLimit
        public Move IterativeDeepening(State state, double timeLimit)
        {
            int depth = 1;
            Stopwatch timer = new Stopwatch();
            Move bestMove = null;
            // start the search
            timer.Start();

            while (true)
            {
                if (timer.ElapsedMilliseconds > timeLimit)
                {
                    if (bestMove == null) // workaround to overcome problem with timer running out too fast with low limits
                    {
                        timeLimit += 10;
                        timer.Reset();
                        timer.Start();
                    }
                    else
                    {
                        return bestMove;
                    }
                }
                Tuple<Move, Boolean> result = IterativeDeepeningAlphaBeta(state, depth, Double.MinValue, Double.MaxValue, timeLimit, timer);
                if (result.Item2) bestMove = result.Item1; // only update bestMove if full recursion
                depth++;
            }
        }
开发者ID:kstrandby,项目名称:2048-Helper,代码行数:29,代码来源:Minimax.cs

示例7: MesureDoubleOperationsPerformance

    //Double operations
    public static TimeSpan MesureDoubleOperationsPerformance(double num, string operation, Stopwatch stopwatch)
    {
        stopwatch.Reset();
        switch (operation)
        {
            case "square root":
                {
                    stopwatch.Start();
                    Math.Sqrt(num);
                    stopwatch.Stop();

                    return stopwatch.Elapsed;
                }
            case "natural logarithm":
                {
                    stopwatch.Start();
                    Math.Log(num);
                    stopwatch.Stop();

                    return stopwatch.Elapsed;
                }
            case "sinus":
                {
                    stopwatch.Start();
                    Math.Sin(num);
                    stopwatch.Stop();

                    return stopwatch.Elapsed;
                }
            default:
                throw new ArgumentException("Invalid operations");
        }
    }
开发者ID:Jarolim,项目名称:TelerikAcademy-1,代码行数:34,代码来源:PerformanceOfSquareRootSinAndNaturalLogarithm.cs

示例8: Main

        static void Main(string[] args)
        {
            Stopwatch sw1 = new Stopwatch();
            sw1.Start();
            using (var db = new DB.MSSQL.courseMSSQLEntities())
            {
                foreach (var i in db.Courses)
                {
                    Console.WriteLine(i.NAME);
                }
            }
            sw1.Stop();
            Console.WriteLine("Using {0} miniseconds.", sw1.ElapsedMilliseconds);

            sw1.Reset();
            sw1.Start();
            using (var db = new DB.MySQL.courseMySQLEntities())
            {
                foreach (var i in db.courses)
                {
                    Console.WriteLine(i.NAME);
                }
            }

            sw1.Stop();
            Console.WriteLine("Using {0} miniseconds.", sw1.ElapsedMilliseconds);
        }
开发者ID:rogerluo,项目名称:testMVC,代码行数:27,代码来源:Program.cs

示例9: PreviewDocumentTypeChanges

        /// <summary>
        /// Checks if there were any changes in document types defined in Umbraco/uSiteBuilder/Both.
        /// Does not check relations between document types (allowed childs and allowable parents)
        /// </summary>
        /// <param name="hasDefaultValues"></param>
        /// <returns></returns>
        public static List<ContentComparison> PreviewDocumentTypeChanges(out bool hasDefaultValues)
        {
            #if DEBUG
            Stopwatch timer = new Stopwatch();
            timer.Start();
            #endif
            // compare the library based definitions to the Umbraco DB
            var definedDocTypes = PreviewDocTypes(typeof(DocumentTypeBase), "");

            #if DEBUG
            timer.Stop();
            StopwatchLogger.AddToLog(string.Format("Total elapsed time for method 'DocumentTypeComparer.PreviewDocumentTypeChanges' - only PreviewDocTypes: {0}ms.", timer.ElapsedMilliseconds));
            timer.Restart();
            #endif

            #if DEBUG
            timer.Start();
            #endif
            hasDefaultValues = _hasDefaultValues;
            // add any umbraco defined doc types that don't exist in the class definitions
            definedDocTypes.AddRange(ContentTypeService.GetAllContentTypes()
                                         .Where(doctype => definedDocTypes.All(dd => dd.Alias != doctype.Alias))
                                         .Select(docType => new ContentComparison { Alias = docType.Alias, DocumentTypeStatus = Status.Deleted, DocumentTypeId = docType.Id }));

            #if DEBUG
            timer.Stop();
            StopwatchLogger.AddToLog(string.Format("Total elapsed time for method 'DocumentTypeComparer.PreviewDocumentTypeChanges' - add any umbraco defined doc types that don't exist in the class definitions: {0}ms.", timer.ElapsedMilliseconds));
            timer.Restart();
            #endif

            return definedDocTypes;
        }
开发者ID:grom8255,项目名称:uSiteBuilder,代码行数:38,代码来源:DocumentTypeComparer.cs

示例10: Main

        static void Main(string[] args)
        {
            InputLoader loader = new InputLoader();
            loader.LoadFile("digits.csv");
            Stopwatch sw = new Stopwatch();

            var heursiticDetection = new HeuristicDetection(10, 5, quantity:50, numberOfPoints:500);
            var hypothesis = new CurrentHypothesis();
            foreach (var input in loader.AllElements()) {
                ///For every new input we extract n points of interest
                ///And create a feature vector which characterizes the spatial relationship between these features
                ///For every heuristic we get a dictionary of points of interest
                DetectedPoints v = heursiticDetection.getFeatureVector(input.Item1);

                ///Compare this feature vector agaist each of the other feature vectors we know about
                sw.Reset();
                sw.Start();
                TestResult r = hypothesis.Predict(v);
                Debug.Print("Prediction: " + sw.Elapsed.Milliseconds.ToString());
                var best= r.BestResult();
                if(best != null && best.Item2 != 0){
                    LogProgress(best.Item1, input.Item2);
                }

                sw.Reset();
                sw.Start();
                hypothesis.Train(v, input.Item2, r);
                Debug.Print("Training: " + sw.Elapsed.Milliseconds.ToString());
                //heursiticDetection.pointsOfInterest.Add(HeuristicDetection.Generate(10, 5, 10));
            }
        }
开发者ID:Amichai,项目名称:DataAnalysis,代码行数:31,代码来源:Program.cs

示例11: Solve

        //Problem 72
        //Consider the fraction, n/d, where n and d are positive integers.
        //If n<d and HCF(n,d)=1, it is called a reduced proper fraction.
        //If we list the set of reduced proper fractions for
        //    d ≤ 8 in ascending order of size, we get:
        //1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5,
        //5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8
        //It can be seen that there are 21 elements in this set.
        //How many elements would be contained in the set of reduced proper
        //fractions for d ≤ 1,000,000?
        //303963552391
        //End of Main (21:34:38.7624901) 4/1/2008 3:03:29 PM
        public static void Solve(int maxD)
        {
            Console.WriteLine("Solving For {0}", maxD);

            Stopwatch sw = new Stopwatch();
            sw.Start();

            decimal cnt = 0;
            for (int d = maxD; d>1; d--)
            {
                int step = (d%2 == 0) ? 2 : 1;
                for (int n = 1; n < d; n += step)
                {
                    if (Divisors.GreatestCommonDivisor(n, d) == 1)
                    {
                        cnt++;
                    }
                }
                if (d % (1+(maxD / 10000)) == 0)
                {
                    Console.WriteLine("{0,8} {1} {2}", d, sw.Elapsed, cnt);
                    sw.Reset();
                    sw.Start();
                }
            }
            Console.WriteLine();
            Console.WriteLine(cnt);
        }
开发者ID:dtuso,项目名称:ProjectE,代码行数:40,代码来源:Problem072.cs

示例12: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                var fact = new MgdServiceFactory();
                MgdRenderingService renSvc = (MgdRenderingService)fact.CreateService(MgServiceType.RenderingService);

                MgResourceIdentifier mdfId = new MgResourceIdentifier(txtMapDefinition.Text);
                var sw = new Stopwatch();
                sw.Start();
                MgdMap map = new MgdMap(mdfId);
                sw.Stop();
                Trace.TraceInformation("Runtime map created in {0}ms", sw.ElapsedMilliseconds);

                map.SetViewScale(Convert.ToDouble(txtScale.Text));
                sw.Reset();
                sw.Start();
                MgByteReader response = renSvc.RenderTile(map, txtBaseGroup.Text, Convert.ToInt32(txtCol.Text), Convert.ToInt32(txtRow.Text));
                sw.Stop();
                Trace.TraceInformation("RenderTile executed in {0}ms", sw.ElapsedMilliseconds);
                new ImageResponseDialog(response).ShowDialog();
            }
            catch (MgException ex)
            {
                MessageBox.Show(ex.ToString(), "Error from MapGuide");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error");
            }
        }
开发者ID:kanbang,项目名称:Colt,代码行数:31,代码来源:RenderTileControl.cs

示例13: Do

 public void Do()
 {
     Console.WriteLine("the linklist:");
     Stopwatch watch = new Stopwatch();
     watch.Start();
     {
         Init();
         {
             for (int k = 0; k < 10000; k++)
             {
                 Linklist.Remove(k);
             }
         }
     }
     watch.Stop();
     Console.WriteLine(watch.ElapsedMilliseconds);
     watch.Reset();
     watch.Start();
     {
         Init();
         {
             for (int k = 0; k < 10000; k++)
             {
                 _List.Remove(k);
             }
         }
     }
     watch.Stop();
     Console.WriteLine(watch.ElapsedMilliseconds);
     Console.ReadLine();
 }
开发者ID:llj098,项目名称:Learning,代码行数:31,代码来源:LinkListOrList.cs

示例14: RunWithContext

        private static void RunWithContext(string topic, int iterations, Federation federation)
        {
            using (RequestContext.Create())
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                string content = federation.GetTopicFormattedContent(new QualifiedTopicRevision(topic), null);
                stopwatch.Stop();

                Console.WriteLine("Rendered first times in {0} seconds", stopwatch.ElapsedMilliseconds / 1000.0F);

                stopwatch.Reset();
                stopwatch.Start();
                content = federation.GetTopicFormattedContent(new QualifiedTopicRevision(topic), null);
                stopwatch.Stop();

                Console.WriteLine("Rendered second time in {0} seconds", stopwatch.ElapsedMilliseconds / 1000.0F);

                stopwatch.Reset();
                stopwatch.Start();
                content = federation.GetTopicFormattedContent(new QualifiedTopicRevision(topic), null);
                stopwatch.Stop();

                Console.WriteLine("Rendered third time in {0} seconds", stopwatch.ElapsedMilliseconds / 1000.0F);
            }
        }
开发者ID:nuxleus,项目名称:flexwikicore,代码行数:26,代码来源:Program.cs

示例15: ShouldPerformFasterThanActivator

        public void ShouldPerformFasterThanActivator()
        {
            // warmup
            for (var i = 0; i < 10; ++i)
            {
                Activator.CreateInstance<ClassWithDefaultConstuctor>();
                ReflectionHelpers.CreateInstance<ClassWithDefaultConstuctor>();
            }
            // warmup
            var count = 0;
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            for (var i = 0; i < 1000000; ++i)
            {
                count += ReflectionHelpers.CreateInstance<ClassWithDefaultConstuctor>().Value;
            }
            stopWatch.Stop();
            var creatorTime = stopWatch.Elapsed;
            stopWatch.Reset();

            stopWatch.Start();
            for (var i = 0; i < 1000000; ++i)
            {
                count += Activator.CreateInstance<ClassWithDefaultConstuctor>().Value;
            }
            stopWatch.Stop();
            var activator = stopWatch.Elapsed;
            Assert.IsTrue(creatorTime < activator);
            Assert.AreEqual(2000000, count);
        }
开发者ID:autotagamerica,项目名称:EasyNetQ,代码行数:31,代码来源:ReflectionHelpersTests.cs


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