time函数

Linux测量程序的运行时间

a 夏天 提交于 2020-01-12 04:14:16
目录 简介 linux时间结构体 time_t struct tm struct timeval time_t使用 struct timeval clock_t 参考资料 简介 最近开始学习《奔跑吧Linux入门版》的实验,想要检测一下程序排序算的时间。因此想写一篇文章详细学习一下linux的时间格式函数。 linux时间结构体 根据这一片文章 time_t tm timeval 和 时间字符串的转换方法 提到了三种时间的结构体 time_t # define __TIME_T_TYPE __SYSCALL_SLONG_TYPE __STD_TYPE __TIME_T_TYPE __time_t ; /* Seconds since the Epoch. */ /* Returned by `time'. */ typedef __time_t time_t ; 属于一个系统的长整型数据。不过精度只有秒 struct tm struct tm { int tm_sec ; /* Seconds. [0-60] (1 leap second) */ int tm_min ; /* Minutes. [0-59] */ int tm_hour ; /* Hours. [0-23] */ int tm_mday ; /* Day. [1-31] */ int tm_mon ; /*

创建装饰器,打印日志信息

百般思念 提交于 2020-01-11 18:27:00
创建装饰器, 要求如下: 创建add_log装饰器, 被装饰的函数打印日志信息; 日志格式为: [字符串时间] 函数名: xxx, 运行时间:xxx, 运行返回值结果:xxx import time import functools def add_log ( func ) : @functools.wraps ( func ) def wrapper ( *args,**kwargs ) : start_time = time.time ( ) res = func ( *args,**kwargs ) end_time = time.time ( ) print ( '[%s] 函数名:%s,运行时间:%.6f,运行返回值的结果' ':%d' % ( time.ctime ( ) ,func.__name__, end_time-start_time,res )) return res return wrapper @add_log def add ( x,y ) : time.sleep ( 1 ) return x+y add ( 1,10 ) 来源: CSDN 作者: Mia1128 链接: https://blog.csdn.net/weixin_45606836/article/details/103935969

如何在Java中将毫秒转换为“ X分钟,x秒”?

风流意气都作罢 提交于 2020-01-11 15:51:45
当用户在我的程序中开始执行某些操作时,我想使用 System.current Time Millis() 记录时间。 当他完成操作后,我将从 start 变量中减去当前的 System.currentTimeMillis() ,我想使用诸如“ XX小时,XX分钟,XX秒”甚至“ XX分钟”之类的人类可读格式显示经过的时间,XX秒”,因为它不太可能花费一个小时。 最好的方法是什么? #1楼 long startTime = System.currentTimeMillis(); // do your work... long endTime=System.currentTimeMillis(); long diff=endTime-startTime; long hours=TimeUnit.MILLISECONDS.toHours(diff); diff=diff-(hours*60*60*1000); long min=TimeUnit.MILLISECONDS.toMinutes(diff); diff=diff-(min*60*1000); long seconds=TimeUnit.MILLISECONDS.toSeconds(diff); //hour, min and seconds variables contains the time elapsed on your

[python] 之 time模块

房东的猫 提交于 2020-01-11 02:27:45
time模块提供了各种功能和方式标识时间值,主要有两种标准标识时间的格式:一种是以时间戳的形式标识,该时间戳是从纪元1970年1月1日0点0分0秒至当前时间的,总共经历的秒数,以浮点小数标识,该纪元时间也依赖于个人的操作系统;另一种标识时间的形式是以一种含有9个元素的元组(标识local time)。该元组的9个元素为: year (four digits, e.g. 1998) month (1-12) day (1-31) hours (0-23) minutes (0-59) seconds (0-59) weekday (0-6, Monday is 0) Julian day (day in the year, 1-366) DST (Daylight Savings Time) flag (-1, 0 or 1) If the DST flag is 0, the time is given in the regular time zone; if it is 1, the time is given in the DST time zone; if it is -1, mktime() should guess based on the date and time. 现对其中常用的时间函数作一简单介绍: asctime([tuple]) -> string

linux 时间相关的一些总结

陌路散爱 提交于 2020-01-11 00:14:48
仅作为内核代码中时间管理模块的笔记,3.10内核,很乱,不喜勿喷。 先有time,后有timer。 常用的time结构有哪些?除了大名鼎鼎的jiffies和jiffies64之外,还有常用的一些结构如下: ktime_t 经常用在timer中, union ktime { s64 tv64; #if BITS_PER_LONG != 64 && !defined(CONFIG_KTIME_SCALAR) struct { # ifdef __BIG_ENDIAN s32 sec, nsec; # else s32 nsec, sec; # endif } tv; #endif }; typedef union ktime ktime_t; /* Kill this */ 经常用在fs中的timespec,低一点精度的timeval,以及时区结构timezone。主要用来做时间戳等。 struct timespec { __kernel_time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ }; struct timeval { __kernel_time_t tv_sec; /* seconds */ __kernel_suseconds_t tv_usec; /* microseconds */ };

Python--面向对象进阶

蹲街弑〆低调 提交于 2020-01-10 13:51:26
一、元类 元类是类的类,是类的模板;元类的实例为类,正如类的实例为对象。类也是对象。 类的本质是对象, 于是可以对类做如下的操作: 你可以将它赋值给一个变量 你可以拷⻉它 你可以为它增加属性 你可以将它作为函数参数进行传递 因为类也是对象,运行时在函数中使用class关键字动态的创建类。 1、通过分支语句动态的创建类 def create_class ( name ) : if name == 'foo' : class Foo ( object ) : pass return Foo else : class Bar ( object ) : pass return Bar cls = create_class ( name = 'foo1' ) print ( cls . __name__ ) Bar 2、通过type函数动态创建类 type函数功能一: 判断对象的类型。 type函数功能二: 动态的创建类。type可以接受一个类的描述作为参数,然后返回一个类。 type函数语法: type(类名,父类名称的元组, 属性信息) def hello ( self ) : print ( "hello" ) Person = type ( 'Person' , ( object , ) , { 'country' : 'China' , 'hello' : hello } ) p1

mysql 中 时间和日期函数

我的未来我决定 提交于 2020-01-10 07:34:24
原文链接:   mysql 中 时间和日期函数 - redfox - 博客园   http://www.cnblogs.com/redfox241/archive/2009/07/23/1529092.html ------------------------------------------------------------------------------------------------------------------------------------------------------ 一、MySQL 获得当前日期时间 函数 1.1 获得当前日期+时间(date + time)函数:now() mysql> select now(); +---------------------+ | now() | +---------------------+ | 2008-08-08 22:20:46 | +---------------------+ 除了 now() 函数能获得当前的日期时间外,MySQL 中还有下面的函数: current_timestamp() ,current_timestamp ,localtime() ,localtime ,localtimestamp -- (v4.0.6) ,localtimestamp() -- (v4.0.6)

SpringBoot时间戳与MySql数据库记录相差14小时排错

寵の児 提交于 2020-01-10 04:49:03
项目中遇到存储的时间戳与真实时间 相差14小时 的现象,以下为解决步骤. 问题 CREATE TABLE `incident` ( `id` int(11) NOT NULL AUTO_INCREMENT, `created_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `recovery_time` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4; 以上为数据库建表语句,其中 created_time 是插入记录时自动设置, recovery_time 需要手动进行设置. 测试时发现, created_time 为正确的北京时间,然而 recovery_time 则与设置时间相差14小时. 尝试措施 jvm时区设置 //设置jvm默认时间 System.setProperty("user.timezone", "UTC"); 数据库时区查询 查看数据库时区设置: show variables like '%time_zone%'; --- 查询结果如下所示: --- system_time_zone: CST --- time_zone:SYSTEM 查询 CST

SQLite数据库C++ API封装

て烟熏妆下的殇ゞ 提交于 2020-01-09 06:19:41
   在一个项目中需要记录目标路径下所有文件的MD5值,由于SQLite简单易用,选择利用它来记录数据。唯一的一张数据表HistoricalMD5,三个属性Dir(完整路径)、Time(时间)、MD5。SQLite常用的C++ API有:sqlite3_open、sqlite3_prepare、sqlite3_bind_parameter_index、sqlite3_bind_text、sqlite3_column_count、sqlite3_step、sqlite3_finalize、sqlite3_close,为了调用方便,对这些函数做了以下封装。 Database.h #include <string> #include <vector> #include <sqlite3.h> using namespace std; class Database { public: Database(const char* filename); ~Database(); void insert(string dir, int time, string MD5); void update(string dir, int time, string MD5); void query(vector<vector<string> > &results); private: sqlite3

python time模块认识

一曲冷凌霜 提交于 2020-01-09 04:29:59
time 模块 -- 时间获取和转换 time 模块提供各种时间相关的功能 在python中, 与时间处理有关的模块包括: time, datatime 以及 calendar 必要说明!: 虽然这个模块总是可用,但并非所有的功能都适合用于各个平台 该模块中定义的大部分函数是调用 C 平台上的同名函数实现, 所以各个平台上实现可能略有不同 一些术语和约定的解释: 时间戳(timestamp)的方式:通常来说,时间戳表示的是从 1970 年 1 月 1 日 00:00:00 开始按秒计算的偏移量(time.gmtime(0))此模块中的函数无法处理 1970 纪元年以前的日期和时间或太遥远的未来 (处理极限取决于 C 函数库,对于 32 位系统来说,是 2038 年) UTC(Coordinated Universal Time,世界协调时)也叫格林威治天文时间,是世界标准时间。在中国为 UTC+8 DST(Daylight Saving Time)即夏令时的意思 一些实时函数的计算精度可能低于它们建议的值或参数,例如在大部分 Unix 系统,时钟一秒钟“滴答”50~100 次 时间元组 (time. struct_time) : gmtime() , localtime() 和 strptime() 以时间元组 (struct_time) 的形式返回 索引值 (index) 属性