ont

rexexp (c version)

ont
Oct 9th, 2012
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <regex.h>
  3.  
  4. #define NUM_MATCHES 2
  5.  
  6. char data[] = "aaaaaaaaaaaaasdffffffffffffffsdfsdfdsfsdfsdfsdfffffffffff 11111 sdfsdfsdfsf aasdfa xxx zzz0bbb-3345sdfsfdsxxxxxxxxxxxxxxxxxxxxxx";
  7.  
  8. int main(void)
  9. {
  10.   regex_t preg;
  11.   regmatch_t pmatch[NUM_MATCHES];
  12.   regcomp( &preg, "b+-([0-9]+)", REG_EXTENDED );
  13.  
  14.   int i;
  15.   for( i = 0; i < 1000000; i++ )
  16.   {
  17.     regexec (&preg, data, NUM_MATCHES, pmatch, 0);
  18.   }
  19.   printf( "%d %d\n", pmatch[ 1 ].rm_so, pmatch[ 1 ].rm_eo );
  20.   regfree (&preg);
  21.   return 0;
  22. }
  23. ----------------------
  24. gcc -O3 -c parse.c -o parse.o
  25. gcc -O3 -o parse parse.o
  26. 95 99
  27.  
  28. real    0m3.068s
  29. user    0m3.063s
  30. sys 0m0.000s
Advertisement
Add Comment
Please, Sign In to add comment