You can search that if anyone do some tests and post a conclusion, like you may see someone compares different ways to conduct table lookup: Table Look-Up by Direct Addressing: Key-Indexing -- Bitmapping -- Hashing (It's really a great paper)
Or you can take some tests by yourself.
There are `find()`, `index()` and `prxmatch()` to search specified string, which one is faster? Here is how I test:
%macro prog_runtime(prog,reps=20,title=Input Prog);
%local _Rep_ _Start_ _End_ _Dur_ _TimeRec_ _SumTime_ _AvgTime_ _MedTime_;
/*Record time consuming of input prog*/
%let _SumTime_ = 0;
%let _TimeRec_ = ;
%do _Rep_ = 1 %to &Reps.;
%let _Start_ = %sysfunc(datetime());
%unquote(&Prog.);
%let _End_ = %sysfunc(datetime());
%let _Dur_ = %sysevalf(&_End_. - &_Start_.);
%let _TimeRec_ = &_TimeRec_. &_Dur_.;
%let _SumTime_ = %sysevalf(&_SumTime_. + &_Dur_.);
%end;
/*Compute median and mean time consuming*/
%let _AvgTime_ = %sysevalf(&_SumTime_/&Reps.);
%let _MedTime_ = %sysfunc(median(%sysfunc(tranwrd(%cmpres(&_TimeRec_.),%str( ),%str(,))) ));
/*Report test result*/
%put ****************************************;
%put Summary of Run Time of &title.;
%put Sum of Run Time: %sysfunc(putn(&_SumTime_.,20.4));
%put Mean of Run Time: %sysfunc(putn(&_AvgTime_.,20.4));
%put Median of Run Time: %sysfunc(putn(&_MedTime_.,20.4));
%put ;
%mend;
option nonotes nosource;
%Prog_RunTime(%nrstr(
data _null_;
x = 'Text with many blanks.';
do i = 1 to 1e7;
y = index(x,'many');
end;
run;
),title=index());
%Prog_RunTime(%nrstr(
data _null_;
x = 'Text with many blanks.';
do i = 1 to 1e7;
y = find(x,'many');
end;
run;
),title=find());
%Prog_RunTime(%nrstr(
data _null_;
x = 'Text with many blanks.';
do i = 1 to 1e7;
y = prxmatch('/many/',x);
end;
run;
),title=prxmatch());
option notes source;
Here is the test result:
****************************************
Summary of Run Time of index()
Sum of Run Time: 2.2940
Mean of Run Time: 0.1147
Median of Run Time: 0.1140
****************************************
Summary of Run Time of find()
Sum of Run Time: 2.8360
Mean of Run Time: 0.1418
Median of Run Time: 0.1420
****************************************
Summary of Run Time of prxmatch()
Sum of Run Time: 8.2410
Mean of Run Time: 0.4121
Median of Run Time: 0.4115
So, if differences of these three functions are ignored, I always choose `index()`.
... View more