Do comments slow down PL/SQL? 备注会降低PL/SQL性能么?

quoted from    http://blogs.techrepublic.com.com/programming-and-development/?p=507&tag=nl.e050 

没时间整理出来。 大家将就看看哈~

I’m not sure where this started, but at work there’s this rumor going around that if you put too many comments in an Oracle PL/SQL package, it impacts performance. That is, the more comments in your code the slower it runs.

I could kind of understand if the language was interpreted because the comments would have to be read in by the interpreter and thus could have an impact on performance. But PL/SQL gets compiled in the database, so I did not see how comments could be a problem.

There’s only one way to really tell, of course, and that’s to run experiments. So, doing my best MythBusters imitation, I decided to take a crack at it.

I started by creating a table called TABLE1 (sorry, I was lazy and just used the table name that SQLDeveloper gave me). The table had three fields: a varchar to store the name of the method and two timestamp fields for the start and end times. The DDL looked something like this:

create table TABLE1
  (  methodname VARCHAR2(255 BYTE),
     starttime TIMESTAMP (6),
     endtime TIMESTAMP (6)
   )

Then I created a package with two methods. The basic code in both methods was identical. Here’s the code from the version without comments:

procedure comments_n AS
    counter integer := 0;
    starttime timestamp;
  BEGIN
    starttime := current_timestamp;    

    while counter < 9999999 loop
      counter := counter + 1;
    end loop;    

    insert into Table1(methodname, starttime, endtime)
    values ('comments_n', starttime, current_timestamp);    

    commit;    

  END comments_n;

The second method, called comments_y, was identical, except I liberally sprinkled single-line and multi-line comments everywhere. And, yes, I put comments inside the loop since that’s where most of the time will be spent in this method.

I then called the methods with a little anonymous block, like this:

begin
  pkg_timingtest.comments_n;
  pkg_timingtest.comments_y;
end;

The first five times through I called the procedure without comments first; then I edited this anonymous block so that the procedure with comments got called first. I re-ran it another five times. When that was done, I averaged up the time differences and grouped them by the method name:

select
  methodname,
  avg ((extract(second from (endtime - starttime))) * 1000) as diff
from table1
group by methodname;

I repeated this experiment several times. On some runs, the method with comments would average faster times than the one without. In those cases where the method with comments was slower on average, it was by just two or three milliseconds, which is not a significant percentage when the average runtime was over 2,400 milliseconds.

I consider this myth busted.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值