标题: SQL2005算术、字符运算 VS SAS9算术、字符运算 [打印本页] 作者: shiyiming 时间: 2006-11-25 08:31 标题: SQL2005算术、字符运算 VS SAS9算术、字符运算 由于SIN函数计算比较耗CPU,也比较经典,故分别实现1千万次SIN运算做比较
sql2005代码:
declare @i int;
declare @x float;
set @i=1;
while @i<=10000000
begin
set @x=sin(@i);
set @i=@i+1;
end;
go
耗时:26秒
sas DATA步代码 :
data _null_;
length i x 8.;
i=1;
do i=1 to 10000000;
x=sin(i);
end;
run;
运行结果:
NOTE: “DATA 语句”所用时间(总处理时间):
实际时间 1.72 秒
CPU 时间 1.70 秒
耗时不到2秒
再对字符进行比较,我选择替换字符串做比较,也是分别实现1千万次进行字符串替换运算做比较
SQL代码
declare @i int;
declare @str varchar(50);
declare @tarStr varchar(50);
set @i=1;
set @str='This is my Test!';
while @i<=10000000
begin
set @tarStr=replace(@str,'my','My');
set @i=@i+1;
end;
print @tarStr;
go
运行结果:耗时2分24秒
SAS DATA步代码
data _null_;
length i 8.;
length str tarstr $50.;
str="This is my Test!";
i=1;
do i=1 to 10000000;
tarstr=tranwrd(str,"my","My");
end;
put tarstr;
run;
运行结果:耗时不到9秒
NOTE: DATA statement used (Total process time):
real time 8.09 seconds
cpu time 8.09 seconds
data _null_;
length i x 8.;
i=1;
do i=1 to 10000000;
x=sin(i);
end;
run;
NOTE: DATA statement used (Total process time):
real time 0.97 seconds
cpu time 0.89 seconds作者: shiyiming 时间: 2007-1-17 16:44 标题: 不错 data _null_;
length i 8.;
length str tarstr $50.;
str="This is my Test!";
i=1;
do i=1 to 10000000;
tarstr=tranwrd(str,"my","My");
end;
put tarstr;
run;
This is My Test!
NOTE: DATA statement used (Total process time):
real time 3.66 seconds
cpu time 3.34 seconds作者: shiyiming 时间: 2007-1-17 23:04 标题: to nfiona 看来SAS又多了个卖点――测算硬件的性能 <!-- s:lol: --><img src="{SMILIES_PATH}/icon_lol.gif" alt=":lol:" title="Laughing" /><!-- s:lol: -->