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