Python-统计执行时间
方法一:datetime.datetime.now()
import datetime
import time
starttime = datetime.datetime.now()
print(starttime.strftime("%Y-%m-%d %H:%M:%S")) time.sleep(2) endtime = datetime.datetime.now()
print(endtime.strftime("%Y-%m-%d %H:%M:%S")) costtime = round((endtime - starttime).total_seconds(),2)
print ('运行时间为:{}秒'.format(costtime))
方法二:time.perf_counter()
# 导入time库
import time
# 代码开始运行
start = time.perf_counter()
print(start) time.sleep(2) # 代码结束运行
end = time.perf_counter()
print(end) # 计算运行时间,单位为秒
print('运行时间为:{}秒'.format(end-start))
Python-统计执行时间的更多相关文章
- python统计元素重复次数
python统计元素重复次数 # !/usr/bin/python3.4 # -*- coding: utf-8 -*- from collections import Counter arr = [ ...
- 简易安装python统计包
PythonCharm简易安装python统计包及 本文介绍使用pythonCharm IDE 来安装Python统计包或一些packages的简单过程,基本无任何技术难度,顺便提一提笔者在安装过程中 ...
- Python统计列表中的重复项出现的次数的方法
本文实例展示了Python统计列表中的重复项出现的次数的方法,是一个很实用的功能,适合Python初学者学习借鉴.具体方法如下:对一个列表,比如[1,2,2,2,2,3,3,3,4,4,4,4],现在 ...
- Python统计日志中每个IP出现次数
介绍了Python统计日志中每个IP出现次数的方法,实例分析了Python基于正则表达式解析日志文件的相关技巧,需要的朋友可以参考下 本脚本可用于多种日志类型 #-*- coding:utf-8 -* ...
- python 统计时间,写日志
python 统计时间使用time模块,写日志使用logging模块,这两个都是标准模板. 测试socket使用socket模块 # 统计时间 ---------------------- impor ...
- python统计文本中每个单词出现的次数
.python统计文本中每个单词出现的次数: #coding=utf-8 __author__ = 'zcg' import collections import os with open('abc. ...
- python统计文档中词频
python统计文档中词频的小程序 python版本2.7 效果如下: 程序如下,测试文件与完整程序在我的github中 #统计空格数与单词数 本函数只返回了空格数 需要的可以自己返回多个值 def ...
- python统计字符串里每个字符的次数
方法一: 推导式 dd="ewq4aewtaSDDSFDTFDSWQrtewtyufashas" print {i:dd.count(i) for i in dd} 方法二: co ...
- python 统计使用技巧
python 统计使用技巧 # 1.不输入回车获取值 注:需要tty模块配合. fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) ...
- python 统计字符串中指定字符出现次数的方法
python 统计字符串中指定字符出现次数的方法: strs = "They look good and stick good!" count_set = ['look','goo ...
随机推荐
- Redis 也支持全文搜索 了?这也太强了
在 2021 年我就了解到 RediSearch 这个项目,并已经把它用于我的开源项目 newbee-mall-pro 中. 就我的使用体验来说,简单场景下,用来平替 Elasticsearch 的使 ...
- java进阶(18)--Enum枚举
一.枚举基本概念 1.引用数据类型 2.每一个值可看作一个常量 3.方法返回结果>2时建议使用枚举,=2建议使用boolean 二.举例说明 1.程序1,方法返回为数字
- appium(三)使用方法
一.appium环境搭建(先决条件) 1.安装JDk 2.安装SDK 参考文章:https://www.cnblogs.com/mrwhite2020/p/13160994.html 3.安装appn ...
- node pressure and pod eviction
0. overview There are too many guides about node pressure and pod eviction, most of them are specifi ...
- 问题--在C++使用strcpy等函数时发生C4996报错
1.问题如下: C4996:'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To ...
- Go-并发安全map
- canal报错nosuchmethod ..bytebuffer
解决方法:更新jdk版本与es一致
- [转帖]Linux内存之Cache
一. Linux内存之Cache 1.1.Cache 1.1.1.什么是Cache? Cache存储器,是位于CPU和主存储器DRAM之间的一块高速缓冲存储器,规模较小,但是速度很快,通常由SRAM( ...
- [转帖]Always-on Profiling for Production Systems
https://0x.tools/ 0x.tools (GitHub) is a set of open-source utilities for analyzing application perf ...
- 监控服务器所有磁盘的inode使用情况
监控服务器所有磁盘的inode使用情况 背景 因为前期数据库开启了审计 但是如果是 DB模式的话 $aud 表的冲突和使用太多了 所以专家建议将审计表放到OS 因为数据库的访问量特别高. 审计的信息又 ...