/* --*- 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); }