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 ...
随机推荐
- 套接字I/O超时设置方法和用select实现超时
注:如无特殊说明,sockfd 原始状态都是阻塞的. 一.使用alarm 函数设置超时 C++ Code 1 2 3 4 5 6 7 8 9 10 11 12 13 void handler( ...
- 使用select函数改进客户端/服务器端程序
一.当我们使用单进程单连接且使用readline修改后的客户端程序,去连接使用readline修改后的服务器端程序,会出现一个有趣的现象,先来看输出: 先运行服务器端,再运行客户端, simba@ub ...
- Linux时间子系统(六) POSIX timer
一.前言 在用户空间接口函数文档中,我们描述了和POSIX timer相关的操作,主要包括创建一个timer.设定timer.获取timer的状态.获取timer overrun的信息.删除timer ...
- nginx实战六
Nginx错误日志 https://coding.net/u/aminglinux/p/nginx/git/blob/master/log/error.md Nginx错误日志平时不用太关注,但是一旦 ...
- Python tuple 函数
描述 Python 元组 tuple() 函数将列表转换为元组. 语法 以下是 tuple 的语法: tuple( seq ) 参数 seq -- 要转换为元组的序列. 返回值 返回元组. 实例 以下 ...
- openssl之EVP系列之9---EVP_Digest系列函数的一个样例
openssl之EVP系列之9---EVP_Digest系列函数的一个样例 ---依据openssl doc/crypto/EVP_DigestInit.pod翻译 (作者:Drago ...
- sphinx 配置文件全解析(转)
sphinx的配置文件是在配置的时候最容易出错的了: 我们先要明白几个概念: source:数据源,数据是从什么地方来的. index:索引,当有数据源之后,从数据源处构建索引.索引实际上就是相当于一 ...
- nginx服务器下 PHP 出现 502 解决方案(转)
nginx出现502有很多原因,但大部分原因可以归结为资源数量不够用,也就是说后端PHP-fpm处理有问题,nginx将正确的客户端请求发给了后端的php-fpm进程,但是因为php-fpm进程的问题 ...
- Smarty之html_options使用心得
<select name="group_id">{html_options options=$member_group selected=$member.group_i ...
- I2C三态门Verilog
http://www.blogbus.com/uyarotxb-logs/206932748.html inout作为输出端口时三态门为选通状态,inout作为输入端口时三态门为高阻态,可通过 ...