C++之程序时间统计类实现
/**********
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++之程序时间统计类实现的更多相关文章
- c++程序时间统计
如下所示,引入<time.h>我们就可以统计时间了: #include<iostream> #include<time.h> #include<windows ...
- Java基础进阶:时间类要点摘要,时间Date类实现格式化与解析源码实现详解,LocalDateTime时间类格式化与解析源码实现详解,Period,Duration获取时间间隔与源码实现,程序异常解析与处理方式
要点摘要 课堂笔记 日期相关 JDK7 日期类-Date 概述 表示一个时间点对象,这个时间点是以1970年1月1日为参考点; 作用 可以通过该类的对象,表示一个时间,并面向对象操作时间; 构造方法 ...
- 整理总结 python 中时间日期类数据处理与类型转换(含 pandas)
我自学 python 编程并付诸实战,迄今三个月. pandas可能是我最高频使用的库,基于它的易学.实用,我也非常建议朋友们去尝试它.--尤其当你本身不是程序员,但多少跟表格或数据打点交道时,pan ...
- H5性能测试,首屏时间统计(Argus)
Argus 腾讯质量开发平台,官网链接:https://wetest.qq.com/product/argus 主要针对性:H5的游戏性能测试 主要介绍: 独家首屏时间统计: 告别人工掐秒 自动统计首 ...
- C++高精度计时器——微秒级时间统计
在C++中,经常需要通过计时来统计性能信息,通过统计的耗时信息,来分析性能瓶颈,通常情况下,可能毫秒级别的时间统计就足够用了,但是在毫厘必争的性能热点的地方,毫秒级别的统计还是不够的,这种情况下,就需 ...
- 代码片段:基于 JDK 8 time包的时间工具类 TimeUtil
摘要: 原创出处:www.bysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢! “知识的工作者必须成为自己时间的首席执行官.” 前言 这次泥瓦匠带来的是一个好玩的基于 JDK ...
- 微信小程序退款 处理类
<?php /** * 微信小程序退款 处理类参考https://www.cnblogs.com/afei-qwerty/p/7922982.html * */ class WeixinRefu ...
- C# 程序内的类数量对程序启动的影响
原文:C# 程序内的类数量对程序启动的影响 版权声明:博客已迁移到 http://lindexi.gitee.io 欢迎访问.如果当前博客图片看不到,请到 http://lindexi.gitee.i ...
- 2018-10-31-C#-程序内的类数量对程序启动的影响
title author date CreateTime categories C# 程序内的类数量对程序启动的影响 lindexi 2018-10-31 14:7:6 +0800 2018-10-1 ...
随机推荐
- Linux中断 - IRQ number和中断描述符
一.前言 本文主要围绕IRQ number和中断描述符(interrupt descriptor)这两个概念描述通用中断处理过程.第二章主要描述基本概念,包括什么是IRQ number,什么是中断描述 ...
- oracle字符串处理函数--待整理
http://www.cnblogs.com/xd502djj/archive/2010/08/11/1797577.html http://blog.csdn.net/qq373591361/art ...
- spring mvc 依赖包
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop&l ...
- 子墨庖丁Android的ActionBar源代码分析 (一)实例化
假设你从事过Androidclient开发,相信你对ActionBar这套框架并不陌生,或者说你并不了解它,可是你应该时不时的要跟它打交道.抛开ActionBar的实现不说,ActionBar实际上是 ...
- Modelsim编译Xilinx器件库的另一种方法
由 xooo 于 星期五, 09/18/2015 - 15:35 发表 以前在用modelsim对Xilinx进行器件库编译时,我用的比较多的是直接在ISE中编译器件库,感觉很方便简单,就是编译时间有 ...
- 【Android】17.0 第17章 服务绑定—本章示例主界面
分类:C#.Android.VS2015: 创建日期:2016-03-03 一.简介 通过服务绑定(Bound Services),可以轻松实现后台服务与界面(UI)的交互. 二.本章示例主界面 1. ...
- maven(6)------maven坐标分析
在不使用maven管理项目,直接使用IDE开发项目时,一个web项目中会涉及到很多技术, 比如struts2,hibernate,spring,mybatis等等,这个时候,我们就需要去各大官网下载不 ...
- linq语法之select distinct Count Sum Min Max Avg
原文来自:http://www.50cms.com/Pages_13_72.aspx 本篇详细说明linq中的Select和Count/Sum/Min/Max/Avg等的用法. Select/Dist ...
- .net core相关博客
http://www.cnblogs.com/artech/蒋金楠,网名Artech,知名IT博主, 微软多领域MVP,畅销IT图书作者,著<WCF全面解析>.<ASP.NET MV ...
- 【转】Java检测字符串是否有乱码
package cn.cnnic.ops.learn; import java.util.regex.Matcher;import java.util.regex.Pattern; public cl ...