2019-02-14
阅读量:
1121
python中如何检测某段代码的运行时间?
问题描述:
- 在对代码进行优化的时候,一个重要标准就是尽可能减少运行时间,那么如何对代码的运行时间进行计算呢?
解决思路:
- 利用time.clock()在代码前后标记,即可计算时间差
import time
import pandas as pd
from sqlalchemy import create_engine
mysql_engine=create_engine('mysql+pymysql://root:18817351931@127.0.0.1:3306/homework?charset=gbk')
print(time.clock())
sql=(
"select a.sname,group_concat(a.sname),a.sage "
" from student a"
" inner join student b on a.sage in "
" (select sage from student where a.sage=b.sage and a.sname!=b.sname)"
" group by a.sname,a.sage"
" order by a.sage"
)
pd.read_sql(sql,mysql_engine)
print(time.clock())

- print(time.clock()-time1)即可实现







评论(0)


暂无数据
推荐帖子
0条评论
0条评论
3条评论