Add a trivial bpf filter benchmark.

This commit is contained in:
Jung-uk Kim 2008-08-25 23:36:24 +00:00
parent 71d7a7dd88
commit 143a24dad7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=182183
2 changed files with 22 additions and 5 deletions

View File

@ -26,7 +26,9 @@ SRCS= ${.CURDIR}/bpf_test.c
CFLAGS+= -g -fno-builtin-abort -I${.CURDIR}/tests
.if defined(LOG_LEVEL)
.if defined(BPF_BENCHMARK)
CFLAGS+= -DBPF_BENCHMARK -DLOG_LEVEL=0
.elif defined(LOG_LEVEL)
CFLAGS+= -DLOG_LEVEL="${LOG_LEVEL}"
.endif
@ -51,10 +53,14 @@ ${TEST}: ${.CURDIR}/tests/${TEST}.h ${SRCS}
all: ${TEST_CASES}
.for TEST in ${TEST_CASES}
.if !defined(LOG_LEVEL) || (${LOG_LEVEL} > 0)
.if defined(BPF_BENCHMARK) || !defined(LOG_LEVEL) || (${LOG_LEVEL} > 0)
@${ECHO} -n "${TEST}: "
.endif
.if defined(BPF_BENCHMARK)
@-time ${.CURDIR}/${TEST}
.else
@-${.CURDIR}/${TEST}
.endif
@rm -f ${.CURDIR}/${TEST}
.endfor

View File

@ -44,6 +44,12 @@ __FBSDID("$FreeBSD$");
#define LOG_LEVEL 1
#endif
#ifdef BPF_BENCHMARK
#define BPF_NRUNS 10000000
#else
#define BPF_NRUNS 1
#endif
static void sig_handler(int);
static int nins = sizeof(pc) / sizeof(pc[0]);
@ -57,7 +63,7 @@ static u_int
bpf_compile_and_filter(void)
{
bpf_jit_filter *filter;
u_int ret;
u_int i, ret;
/* Do not use BPF JIT compiler for an empty program */
if (nins == 0)
@ -72,7 +78,8 @@ bpf_compile_and_filter(void)
exit(FATAL);
}
ret = (*(filter->func))(pkt, wirelen, buflen);
for (i = 0; i < BPF_NRUNS; i++)
ret = (*(filter->func))(pkt, wirelen, buflen);
bpf_destroy_jit_filter(filter);
@ -148,6 +155,9 @@ bpf_validate(const struct bpf_insn *f, int len)
int
main(void)
{
#if !defined(BPF_JIT_COMPILER)
u_int i;
#endif
u_int ret;
int sig;
#ifdef BPF_VALIDATE
@ -178,7 +188,8 @@ main(void)
#ifdef BPF_JIT_COMPILER
ret = bpf_compile_and_filter();
#else
ret = bpf_filter(pc, pkt, wirelen, buflen);
for (i = 0; i < BPF_NRUNS; i++)
ret = bpf_filter(pc, pkt, wirelen, buflen);
#endif
if (ret != expect) {
if (verbose > 1)