home *** CD-ROM | disk | FTP | other *** search
- /*
- ** regbench.c
- ** quick-n-dirty example of regexp.library usage
- ** (L) 1998 by Matthias Bethke
- */
-
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/regexp.h>
-
- struct RegexpBase *RegexpBase;
-
- LONG main(void)
- {
- STRPTR pat="b.*x...a+w$"; // the pattern
- LONG i; // a counter
- regexp *re; // handle for the compiled expression
- struct DateStamp ds[2]; // for timing
- LONG tix; // elapsed ticks
- LONG rcode=RETURN_OK; // program return code
-
- /* open regexp.library */
- if(RegexpBase = (struct RegexpBase*)OpenLibrary("regexp.library",37))
- {
- Printf("Compiling pattern once, matching 50000 times\n");
- /* take current time */
- DateStamp(ds);
- /* compile the pattern to internal format */
- if(re = RegComp(pat))
- {
- for(i=0; i<25000; i++)
- {
- RegExec(re,"blllllxabcaw"); // one pattern that matches
- RegExec(re,"bhh1234567890hhx222w"); // one that doesn't - jut 2 b fair :)
- }
- /* free the regexp */
- RegFree(re);
- } else
- {
- Printf("Can't compile pattern \"%s\"!\n",pat);
- rcode = RETURN_ERROR;
- }
- /* timing stuff */
- DateStamp(ds+1);
- tix = 50*60 * (ds[1].ds_Minute - ds[0].ds_Minute);
- tix += (ds[1].ds_Tick - ds[0].ds_Tick);
- tix <<= 1;
-
- Printf("Time: %ld.%02lds (%ld ticks), %ld matches per second\n",tix/100,tix%100,tix>>1,5000000/tix);
- CloseLibrary((struct Library*)RegexpBase);
- } else
- {
- Printf("Can't open regexp.library V37+!\n");
- rcode = RETURN_FAIL;
- }
- return rcode;
- }
-