由于sin函數計算比較耗cpu,也比較經典,故分別實現1千萬次sin運算做比較
sql2005代碼:
declare @i int;
declare @x float;
set @i=1;
while @i<=10000000
begin
set @x=sin(@i);
set @[email protected]+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 @[email protected]+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
初步總結:
進行一千萬次sin運算時,sql2005耗時26秒,sas不到2秒,差不多相差13倍
進行一千萬次字符替換運算時,sql2005耗時144秒,sas不到9秒,差不多相差16倍
可以看出,sas的數據處理能力可以說是超強,在這方面可以說任何當前數據庫都不能相比
如果不是由于sas本身產品的限制,說不定早就在中國市場上流行了
:) 如果有人想把sas做的etl轉為用sql2005做etl時,可要考慮客戶的感受了,想想如果一下子由原來的十幾天的數據加載變成幾個月的數據加載,你就頭疼把;當然如果只是小數據量加載之間的轉換,還是沒問題的
比較有意思的是,sas的merge操作一直以來都是要求輸入的數據要先按指定字段進行排序才能merge,現在sql2005提供的merge組件也有了這樣的要求,有點像終于找到黨組織的感覺了
新聞熱點
疑難解答