|
Subject: Re: Macro Problem
Summary: Roger Deangelis' contention that calls to format are faster
than %IFs appears to be correct.
Respondent: Ian Whitlock <whitloi1@westat.com>
Like Don Stanley I thought the use of %SYSFUNC would take too much
time. Thanks Roger for the correction.
Here is my log on a Compac Prolinea 486/50 for a slightly different
version of Roger's code which gives the best chance to the %IFs.
409 /* sysfunc.sas - format vs %if in macro */
410 %macro tst2;
411
412 %let stime=%sysfunc ( time() );
413 %put begin &stime ;
414
415 %do j=1 %to 999;
416
417 %if &j gt 100 %then %let i=0&j;
418 %else %if &j gt 10 %then %let i=00&j;
419 %else %let i=000&j;
420
421 %end;
422
423 %let etime=%sysfunc ( time () ) ;
424 %put end = &etime ;
425
426 %let dur=%sysevalf(&etime-&stime);
427 %put dur concode =&dur seconds;
428
429 %mend tst2;
430
431
432 %macro tst1;
433
434 %let stime=%sysfunc ( time () ) ;
435 %put begin = &stime ;
436
437 %do j=1 %to 999;
438
439 %let i=%sysfunc(putn(&j,z4));
440
441 %end;
442
443 %let etime=%sysfunc ( time () ) ;
444 %put end = &etime ;
445
446 %let dur=%sysevalf(&etime-&stime);
447 %put dur sysfunc =&dur seconds;
448
449 %mend tst1;
450
451 %tst1
begin = 57195.06
end = 57205.28
dur sysfunc =10.22 seconds
452
453 %tst2
begin 57205.61
end = 57218.63
dur concode =13.02 seconds
The %IFs were not far behind but using Roger's form of %IF code the
times for %Ifs about doubled while the %SYSFUNC times remained stable.
This fact alone if enough to convince me that Roger is right again.
And thanks to Jeff Polzin and his team for providing what now looks
like such an efficient tool.
Ian Whitlock
--------------------------------------------------------------------
Author: Roger Deangelis <deangel@HORIZSYS.COM> at internet-e-mail
Date: 4/3/96 3:09 PM
Priority: Normal
BCC: WHITLOI1 at REC
TO: SAS-L@uga.cc.uga.edu at Internet-E-Mail
Subject: Re: Macro Problem
------------------------------- Message Contents -------------------------------
Don writes that
%sysfunc(putn(&j,z4)); is extreemely inefficient.
This was also my first thought. I was not able to accurately test the
case for j=1 to 9 since the results were inconclusive due to system load.
However for cases 1-100 and 1-1000 usings SAS611 on a SUN1000e the code below
gave:
If statements Sysfunc
1-1000 3.0 seconds 2.5 seconds
1-100 0.5 seconds 0.3 seconds
I realize this is not answer the question (1-9) case. Also I am a little
concerned about how and when Jeffs %datetime executes. I ran with runs
after each datetime call.
I am still puzzled by the results!!!!
Roger DeAngelis
============================== TEST CODE Below ============================
%utlnopts;
%macro tst2;
%let stime=%datetime;
%do j=1 %to 1000;
%if &j lt 10 %then %let i=000&j;
%else &j lt 100 %then %let i=00&j;
%else &j lt 1000 %then %let i=0&j;
%else %let i=&j;
%end;
%let etime=%datetime;
%let dur=%sysevalf(&etime-&stime);
%put dur concode =&dur seconds;
%mend tst2;
%tst2;
run;
%macro tst1;
%let stime=%datetime;
%do j=1 %to 1000;
%let i=%sysfunc(putn(&j,z4));
%end;
%let etime=%datetime;
%let dur=%sysevalf(&etime-&stime);
%put dur sysfunc =&dur seconds;
%mend tst1;
%tst1;
run;
From owner-sas-l@UGA.CC.UGA.EDU Wed Apr 3 06:16 EST 1996
>Received: from uga.cc.uga.edu by netcomsv.netcom.com with SMTP (8.6.12/SMI-4.1)
id WAA06323; Tue, 2 Apr 1996 22:37:03 -0800
Date: Mon, 1 Apr 1996 20:13:05 GMT
From: Don Stanley <dstanle@IBM.NET>
Subject: Re: Macro Problem
To: Multiple recipients of list SAS-L <SAS-L@uga.cc.uga.edu>
This is an extremely inefficient way to do a simple task. It cause formats to
be
loaded and unnecessary arithmetic operations to be carried out.
Much better to do ...
%if &i < 10 %then %let j=0&i ; %else %let j=&i ;
and then use &j in the macro
Don
|