您的位置:首页 > 其它

GDB常用命令

2010-05-10 22:51 267 查看
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: