Write some matching benchmarks
This commit is contained in:
parent
e4d3b08bf2
commit
97529fdd2b
@ -14,3 +14,7 @@ function(add_benchmark_suites)
|
|||||||
add_benchmark_suite(${source})
|
add_benchmark_suite(${source})
|
||||||
endforeach()
|
endforeach()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
add_benchmark_suites(
|
||||||
|
matching_benchmarks.c
|
||||||
|
)
|
||||||
|
52
benchmarks/matching_benchmarks.c
Normal file
52
benchmarks/matching_benchmarks.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Camden Dixie O'Brien
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "benchmarking.h"
|
||||||
|
#include "compile.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#define LEN 100
|
||||||
|
#define RANGE_FIRST 'a'
|
||||||
|
#define RANGE_LAST 'z'
|
||||||
|
|
||||||
|
#define CLAMP_CHAR(x) (RANGE_FIRST + x % (RANGE_LAST - RANGE_FIRST + 1))
|
||||||
|
|
||||||
|
#define RUN_MATCHING_BENCHMARK(reps, name, regex) \
|
||||||
|
do { \
|
||||||
|
fsa_t fsa; \
|
||||||
|
compile(regex, strlen(regex), &fsa); \
|
||||||
|
RUN_BENCHMARK(reps, name, matching_benchmark, &fsa); \
|
||||||
|
fsa_free(&fsa); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
static void matching_benchmark(const fsa_t *fsa)
|
||||||
|
{
|
||||||
|
char s[LEN];
|
||||||
|
for (int j = 0; j < LEN; ++j)
|
||||||
|
s[j] = CLAMP_CHAR(rand());
|
||||||
|
|
||||||
|
START_CLOCK();
|
||||||
|
fsa_accepts(fsa, s, LEN);
|
||||||
|
STOP_CLOCK();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
srand(tv.tv_usec);
|
||||||
|
|
||||||
|
BENCHMARKING_BEGIN();
|
||||||
|
|
||||||
|
RUN_MATCHING_BENCHMARK(10000, "foo or bar", ".*(foo|bar).*");
|
||||||
|
RUN_MATCHING_BENCHMARK(10000, "regex #1", ".*(abc!?)*|dd+.*");
|
||||||
|
RUN_MATCHING_BENCHMARK(10000, "regex #2", ".*(l|wh)?[aeiou]+.*");
|
||||||
|
|
||||||
|
return BENCHMARKING_END();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user