Compare commits

...

3 Commits

Author SHA1 Message Date
de8cbb23b5 Run benchmarks 100000x times instead of 10000 2024-11-10 16:30:09 +00:00
601829bd29 Increase length of benchmark strings 2024-11-10 16:29:44 +00:00
4131af3912 Assign match result to volatile in benchmarks
This is needed to avoid the compiler eliding the call in
highly-optimised builds.
2024-11-10 16:28:38 +00:00

View File

@ -11,7 +11,7 @@
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
#define LEN 100 #define LEN 1000
#define RANGE_FIRST 'a' #define RANGE_FIRST 'a'
#define RANGE_LAST 'z' #define RANGE_LAST 'z'
@ -31,9 +31,11 @@ static void matching_benchmark(const fsa_t *fsa)
for (int j = 0; j < LEN; ++j) for (int j = 0; j < LEN; ++j)
s[j] = CLAMP_CHAR(rand()); s[j] = CLAMP_CHAR(rand());
volatile bool match;
START_CLOCK(); START_CLOCK();
fsa_accepts(fsa, s, LEN); match = fsa_accepts(fsa, s, LEN);
STOP_CLOCK(); STOP_CLOCK();
(void)match;
} }
int main(void) int main(void)
@ -44,9 +46,9 @@ int main(void)
BENCHMARKING_BEGIN(); BENCHMARKING_BEGIN();
RUN_MATCHING_BENCHMARK(10000, "foo or bar", ".*(foo|bar).*"); RUN_MATCHING_BENCHMARK(100000, "foo or bar", ".*(foo|bar).*");
RUN_MATCHING_BENCHMARK(10000, "regex #1", ".*(abc!?)*|dd+.*"); RUN_MATCHING_BENCHMARK(100000, "regex #1", ".*(abc!?)*|dd+.*");
RUN_MATCHING_BENCHMARK(10000, "regex #2", ".*(l|wh)?[aeiou]+.*"); RUN_MATCHING_BENCHMARK(100000, "regex #2", ".*(l|wh)?[aeiou]+.*");
return BENCHMARKING_END(); return BENCHMARKING_END();
} }