shell 脚本和python操作oracle性能比对
2018-01-09 16:53
489 查看
刚开始学习python,对oracle进行简单操作,好奇心之下,比较一下和shell的性能差别,变量控制没有那么严格,都是单线程。
表里100万条数据,先把主键查出来,再根据主键删除掉,计算总共用的时间。
python脚本:
begin=time.clock()
print("begin at:"+str(begin))
con = db.connect(DBUID)
cur=con.cursor()
cur.execute("select serv_id from zhangbo_serv")
res=cur.fetchall()
for i in res:
bind_list={'id':i[0]}
cur.execute("delete from zhangbo_serv where serv_id = :id",bind_list)
con.commit()
end=time.clock()
print("end at :"+str(end))
print("cost:"+str(end-begin))
花费时间:
shell脚本:
get_serv_id()
{
sqlplus $DBUID<<!
select 'xxx delete from zhangbo_serv where serv_id = '||serv_id from zhangbo_serv;
exit;
!
}
getTiming()
{
start=$1
end=$2
start_s=$(echo $start | cut -d '.' -f 1)
start_ns=$(echo $start | cut -d '.' -f 2)
end_s=$(echo $end | cut -d '.' -f 1)
end_ns=$(echo $end | cut -d '.' -f 2)
time=$(( ( 10#$end_s - 10#$start_s ) * 1000 + ( 10#$end_ns / 1000000 - 10#$start_ns / 1000000 ) ))
echo "$time ms"
}
begin=$(date +%s.%N)
echo "begin at:" $begin
echo "sqlplus $DBUID<<!">./delete.sh
get_serv_id|grep ^xxx|awk '{print$2,$3,$4,$5,$6,$7,$8}'>>./delete.sh
echo "commit;">>./delete.sh
echo "exit;">>./delete.sh
echo "!">>./delete.sh
sh delete.sh
end=$(date +%s.%N)
echo "end at:" $end
runtime=$(getTiming $begin $end)
echo "cost:"$runtime
花费时间:
虽然shell里其他一些东西没有严格控制,也占用了一定的时间,但是,差了这么大的数量级,其他的完全可以忽略了。而且,shell需要将select出来的sql语句重定向到新的shell脚本再执行,明显复杂的多。看来,用python还是很有必要的
表里100万条数据,先把主键查出来,再根据主键删除掉,计算总共用的时间。
python脚本:
begin=time.clock()
print("begin at:"+str(begin))
con = db.connect(DBUID)
cur=con.cursor()
cur.execute("select serv_id from zhangbo_serv")
res=cur.fetchall()
for i in res:
bind_list={'id':i[0]}
cur.execute("delete from zhangbo_serv where serv_id = :id",bind_list)
con.commit()
end=time.clock()
print("end at :"+str(end))
print("cost:"+str(end-begin))
花费时间:
shell脚本:
get_serv_id()
{
sqlplus $DBUID<<!
select 'xxx delete from zhangbo_serv where serv_id = '||serv_id from zhangbo_serv;
exit;
!
}
getTiming()
{
start=$1
end=$2
start_s=$(echo $start | cut -d '.' -f 1)
start_ns=$(echo $start | cut -d '.' -f 2)
end_s=$(echo $end | cut -d '.' -f 1)
end_ns=$(echo $end | cut -d '.' -f 2)
time=$(( ( 10#$end_s - 10#$start_s ) * 1000 + ( 10#$end_ns / 1000000 - 10#$start_ns / 1000000 ) ))
echo "$time ms"
}
begin=$(date +%s.%N)
echo "begin at:" $begin
echo "sqlplus $DBUID<<!">./delete.sh
get_serv_id|grep ^xxx|awk '{print$2,$3,$4,$5,$6,$7,$8}'>>./delete.sh
echo "commit;">>./delete.sh
echo "exit;">>./delete.sh
echo "!">>./delete.sh
sh delete.sh
end=$(date +%s.%N)
echo "end at:" $end
runtime=$(getTiming $begin $end)
echo "cost:"$runtime
花费时间:
虽然shell里其他一些东西没有严格控制,也占用了一定的时间,但是,差了这么大的数量级,其他的完全可以忽略了。而且,shell需要将select出来的sql语句重定向到新的shell脚本再执行,明显复杂的多。看来,用python还是很有必要的
相关文章推荐
- shell脚本操作oracle删除表空间、创建表空间、删除用户
- shell脚本操作oracle删除表空间、创建表空间、删除用户
- Monkeyrunner 写脚本的技巧(shell 命令,文件操作)---关键点,python创建以时间命名的文件夹
- 运维中的日志切割操作梳理(Logrotate/python/shell脚本实现)
- python ,shell 脚本 执行同样操作,花费时间效率对比
- shell脚本操作oracle删除表空间、创建表空间、删除用户
- python shell脚本(主要讲管道操作的支持)
- Python 和 bash shell脚本(python和shell, python中文件操作, python中目录操作)
- 运维中的日志切割操作梳理(Logrotate/python/shell脚本实现)
- oracle用shell脚本链接数据库进行操作
- impala-shell脚本python环境缺少依赖包
- perl 、shell、python之shell脚本入门
- oracle 性能优化操作五:尽量去掉 "<>"
- 在cmd下运行Python脚本+如何使用Python Shell
- oracle 性能优化操作十: 分解复杂查询,用常量代替变量
- shell脚本下所有的重定向操作
- Oracle性能调优-优化排序操作
- 【转】oracle对BLOB类型数据的操作与性能问题
- 在 shell 脚本获取 ip、数字转换等网络操作
- ORACLE备份、还原总结(2====digest【含操作脚本】=====by DQ20110608)