X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib_internal%2Ftestsuite%2Fcrypto-speed.c;fp=lib_internal%2Ftestsuite%2Fcrypto-speed.c;h=0672a279d030bbf17100bfcaab670a929b6270e5;hb=df13e5523df231124858003c93bdaa3b7a361f07;hp=0000000000000000000000000000000000000000;hpb=e34aa37caea43be4282606b6460b7d106e928e7e;p=util-vserver.git diff --git a/lib_internal/testsuite/crypto-speed.c b/lib_internal/testsuite/crypto-speed.c new file mode 100644 index 0000000..0672a27 --- /dev/null +++ b/lib_internal/testsuite/crypto-speed.c @@ -0,0 +1,112 @@ +/* --*- c -*-- + * Copyright (C) 2008 Enrico Scholz + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 and/or 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#define ENSC_TESTSUITE + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include + + +static void +do_benchmark(char const *meth_name) +{ + struct { + size_t block_size; + size_t blocks; + } const DATA_SIZES[] = { + { 0, 1 }, + { 0, 1024*1024 }, + { 16, 1 }, + { 16, 1024*1024 }, + { 1024, 16 }, + { 1024, 16*1024 }, + { 1024*1024, 16 }, + { 1024*1024, 100 }, + { 1024*1024, 1000 } + }; + + ensc_hash_method const *m = ensc_crypto_hash_find(meth_name); + ensc_hash_context ctx; + size_t d_len = m ? ensc_crypto_hash_get_digestsize(m) : 0; + char digest[d_len]; + char * buf; + size_t i; + + assert(m); + assert(ensc_crypto_hashctx_init(&ctx, m)==0); + + for (i=0; i %2lu.%09lus, %'15llu bytes/s\n", + meth_name, DATA_SIZES[i].blocks, bs, + delta.tv_sec, delta.tv_nsec, (unsigned long long)(bps)); + } + + ensc_crypto_hashctx_free(&ctx); +} + +int main() +{ + char const * const METHS[] = { + "md5", "sha1", "sha256", "sha512", NULL + }; + char const * const * meth; + + ensc_crypto_init(); + setlocale(LC_NUMERIC, ""); /* needed for the thousands grouping */ + + for (meth=METHS+0; *meth; ++meth) + do_benchmark(*meth); +}