/**********
TimeCounter.h
huangsy13@gmail.com
**********/
#ifndef TIMECOUNTER
#define TIMECOUNTER #include <iostream>
#include <cstring>
#include <ctime>
#include <sstream>
#include <cstdlib>
#include "FileStruct.h" using namespace std; struct TimeCounter{
time_t beginT;
time_t nowT;
int totalTask;
int completeTask;
string lastUseT;
void setUp(int totalTask0){
totalTask = totalTask0;
nowT = ;
beginT = time(NULL);
}
bool update(int taskNow){
nowT = time(NULL);
completeTask = taskNow;
if (lastUseT == useTime() && completeTask < totalTask){
return false;
}
else{
lastUseT = useTime();
return true;
}
}
string useTime(){
int r = nowT - beginT;
return getTimeStr(r);
}
string restTime(){
if(completeTask == ){
return "unknow";
}
int restTT = double(totalTask-completeTask)*double(nowT-beginT)/double(completeTask);
return getTimeStr(restTT);
}
string getTimeStr(int r){
int rs = r;
int rh = rs/;
int rm = rs/;
string str;
if (rh != ){
str = numToStr(rh) + " hours ";
}
if (rs >= ){
str += numToStr(rm%) + " minutes ";
}
str += numToStr(rs%) + " seconds";
return str;
}
string percent(){
int p = *completeTask/totalTask;
return numToStr(p)+"%";
}
void print(bool clear){
if (clear) system("clear");
cout << "use time " << useTime()<<endl;
cout << "rest Time "<< restTime() <<endl;
cout << "complete " << percent() << endl;
}
void updateAndPrint(int nn,bool clear = true){
if(update(nn)){
print(clear);
}
}
}; #endif /*********
main.cpp
huangsy13@gmail.com
*********/
#include <iostream>
#include <cstring>
#include <ctime>
#include <sstream>
#include <cstdlib>
#include "TimeCounter.h" using namespace std; int main(){
TimeCounter T;
int totalTask = ;
T.setUp(totalTask);
int taskNow = ;
while(taskNow < totalTask){
T.updateAndPrint(++taskNow);
for (int i = ; i < ; i++){
int a = ;
int b = ;
while(a != b){
a++;
}
}
}
}

C++之程序时间统计类实现的更多相关文章

  1. c++程序时间统计

    如下所示,引入<time.h>我们就可以统计时间了: #include<iostream> #include<time.h> #include<windows ...

  2. Java基础进阶:时间类要点摘要,时间Date类实现格式化与解析源码实现详解,LocalDateTime时间类格式化与解析源码实现详解,Period,Duration获取时间间隔与源码实现,程序异常解析与处理方式

    要点摘要 课堂笔记 日期相关 JDK7 日期类-Date 概述 表示一个时间点对象,这个时间点是以1970年1月1日为参考点; 作用 可以通过该类的对象,表示一个时间,并面向对象操作时间; 构造方法 ...

  3. 整理总结 python 中时间日期类数据处理与类型转换(含 pandas)

    我自学 python 编程并付诸实战,迄今三个月. pandas可能是我最高频使用的库,基于它的易学.实用,我也非常建议朋友们去尝试它.--尤其当你本身不是程序员,但多少跟表格或数据打点交道时,pan ...

  4. H5性能测试,首屏时间统计(Argus)

    Argus 腾讯质量开发平台,官网链接:https://wetest.qq.com/product/argus 主要针对性:H5的游戏性能测试 主要介绍: 独家首屏时间统计: 告别人工掐秒 自动统计首 ...

  5. C++高精度计时器——微秒级时间统计

    在C++中,经常需要通过计时来统计性能信息,通过统计的耗时信息,来分析性能瓶颈,通常情况下,可能毫秒级别的时间统计就足够用了,但是在毫厘必争的性能热点的地方,毫秒级别的统计还是不够的,这种情况下,就需 ...

  6. 代码片段:基于 JDK 8 time包的时间工具类 TimeUtil

    摘要: 原创出处:www.bysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢! “知识的工作者必须成为自己时间的首席执行官.” 前言 这次泥瓦匠带来的是一个好玩的基于 JDK ...

  7. 微信小程序退款 处理类

    <?php /** * 微信小程序退款 处理类参考https://www.cnblogs.com/afei-qwerty/p/7922982.html * */ class WeixinRefu ...

  8. C# 程序内的类数量对程序启动的影响

    原文:C# 程序内的类数量对程序启动的影响 版权声明:博客已迁移到 http://lindexi.gitee.io 欢迎访问.如果当前博客图片看不到,请到 http://lindexi.gitee.i ...

  9. 2018-10-31-C#-程序内的类数量对程序启动的影响

    title author date CreateTime categories C# 程序内的类数量对程序启动的影响 lindexi 2018-10-31 14:7:6 +0800 2018-10-1 ...

随机推荐

  1. Linux时间子系统(十五) clocksource

    一.前言 和洋葱一样,软件也是有层次的,内核往往需要对形形色色的某类型的驱动进行抽象,屏蔽掉其具体的特质,获取该类驱动共同的逻辑,而又根据这些逻辑撰写该类驱动的抽象层.嵌入式系统总是会提供timer的 ...

  2. [Android&amp;Java]浅谈设计模式-代码篇:观察者模式Observer

    观察者,就如同一个人,对非常多东西都感兴趣,就好像音乐.电子产品.Game.股票等,这些东西的变化都能引起爱好者们的注意并时刻关注他们.在代码中.我们也有这种一种方式来设计一些好玩的思想来.今天就写个 ...

  3. GO1.6语言学习笔记1-基础篇

    一.GO语言优势   可直接编译成机器码,Go编译生成的是一个静态可执行文件,除了glibc外没有其他外部依赖 静态类型语言,但是有动态语言的感觉 语言层面支持并发.Goroutine和channel ...

  4. BZOJ 2466 中山市选2009 树 高斯消元+暴力

    题目大意:树上拉灯游戏 高斯消元解异或方程组,对于全部的自由元暴力2^n枚举状态,代入计算 这做法真是一点也不优雅... #include <cstdio> #include <cs ...

  5. cocos2dx 3.x 相机机制

    一,3.x相机使用方法: CCSize winSize=CCDirector::sharedDirector()->getWinSize(); Camera* camera=Camera::cr ...

  6. RUBY Error: Please update your PATH to include build tools or download the DevKit

    出错的原因是安装XXXXX的时候,需要build tools,但系统中没有.出错信息中同时也给出了解决的法案: 1. 到 http://rubyinstaller.org/downloads/ 去下载 ...

  7. mybatis 一二事(1) - 简单介绍

    mybatis呢是一个orm数据库框架,非常适合新人学,门槛相对较低 本人呢曾经是先做的hibernate,后接触的mybatis,接触mabatis前我比较抵触,为啥呢, 当时喜欢hibernate ...

  8. AAA含义图解

    来源: <FreeRADIUS Beginner's Guide> 这本书 1,认证 2,授权 3,审计

  9. python鸭子类型(duck type)

    1.什么是鸭子类型顾名思义,就是看起来像鸭子的类型,就可以叫做鸭子类型所以,鸭子类型是一种不严格的类型,弱类型有相同方法的类型,可以归为一类鸭子.2.鸭子类型示例 class dog: def run ...

  10. laravel 拾遗 中间件

    Problem You want to add middleware to your application but don't know where to begin.     Solution C ...