zoukankan      html  css  js  c++  java
  • 统计操作耗时的类

     //该类用于计算操作的耗时.
        public class RunTime
        {
            DateTime start = DateTime.Now;
            TimeSpan elapsed = new TimeSpan(0);

            public override string ToString()
            {
                elapsed = (DateTime.Now - start);
                if (elapsed.TotalMilliseconds > 600000.0)
                {
                    //当总耗时超过10分钟时,返回格式: 时:分:秒.
                    return d(3600000) + ":" + d(600000) + d(60000) + ":" + d(10000) + d(1000);
                }
                else
                {
                    //当总耗时小于10分钟时,返回格式:分:秒.毫秒
                    return d(60000) + ":" + d(10000) + d(1000) + "." + d(100) + d(10);
                }
            }

            //传入一个位的毫秒的倍数级,然后返回在该位上的数字值,并将总耗时减去该位上的值.
            protected internal virtual string d(long scale)
            {
                long report = (long)Math.Floor(elapsed.TotalMilliseconds / (double)scale);
                long remaining = (long)Math.Floor(elapsed.TotalMilliseconds - (double)(report * scale));
                elapsed = new TimeSpan(remaining * 10000); // 1ms = 10000ticks
                return report.ToString();
            }
        }

  • 相关阅读:
    STM32系列命名规则
    在使用MOS管时要注意的问题
    LED汽车前大灯
    Linux Makefile analysis for plain usr
    Linux Kernel Makefile Test
    linux源码Makefile的详细分析
    "The connection for the USB device '###' was unsuccessful. The device is currently in use"
    Allegro使用技巧
    Integrated Circuit Intro
    ADC/DAC的一些参数
  • 原文地址:https://www.cnblogs.com/robyn/p/3729319.html
Copyright © 2011-2022 走看看