Commit e8db5894 authored by Nils Goroll's avatar Nils Goroll

add a trivial benchmark function

parent 68467fcd
# looks like -*- vcl -*-
varnishtest "SHA256 bench"
# hmac object
varnish v1 -vcl {
import blobdigest from "${vmod_topbuild}/src/.libs/libvmod_blobdigest.so";
import blob;
backend b { .host = "${bad_ip}"; }
sub vcl_init {
# RFC4231 test cases
new k1 = blob.blob(HEX,
"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
new rfc4231t1 = blobdigest.hmac(SHA256, k1.get());
new k6 = blob.blob(HEX,
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.dur = rfc4231t1.hmac_bench(1000000, k6.get());
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
} -run
......@@ -34,6 +34,7 @@
#include "vcl.h"
#include "vas.h"
#include "vsb.h"
#include "vtim.h"
#include "vcc_if.h"
#include "vmod_blobdigest.h"
......@@ -565,6 +566,27 @@ vmod_hmac_hmac(VRT_CTX, struct vmod_blobdigest_hmac *h, VCL_BLOB msg)
h->vcl_name, "hmac");
}
VCL_DURATION
vmod_hmac_hmac_bench(VRT_CTX, struct vmod_blobdigest_hmac *h, VCL_INT n,
VCL_BLOB msg)
{
double t0, t1;
uintptr_t snap;
if (n <= 0) {
ERR(ctx, "number of rounds must be greater than zero");
return (-1);
}
snap = WS_Snapshot(ctx->ws);
t0 = VTIM_mono();
while (n--) {
WS_Reset(ctx->ws, snap);
(void) vmod_hmac_hmac(ctx, h, msg);
}
t1 = VTIM_mono();
return (t1 - t0);
}
VCL_VOID
vmod_hmac__fini(struct vmod_blobdigest_hmac **hmacp)
{
......
......@@ -410,6 +410,10 @@ Example::
return(synth(401));
}
$Method DURATION .hmac_bench(INT n, BLOB msg)
Run `n` rounds of ``.hmac`` and return the net total duration.
$Function BLOB hmacf(ENUM {MD5, SHA1, SHA224, SHA256, SHA384, SHA512, SHA3_224,
SHA3_256, SHA3_384, SHA3_512} hash, BLOB key,
BLOB msg)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment