monotone

monotone Mtn Source Tree

Root/src/sha1.cc

1// Copyright (C) 2006 Nathaniel Smith <njs@pobox.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10// This file holds a registry of different SHA-1 implementations, and lets us
11// benchmark them.
12
13#include "base.hh"
14#include <botan/botan.h>
15#include <botan/sha160.h>
16
17// Botan 1.7.23+ and 1.8.x specific sha1 benchmarking code uses botan's
18// own timer and measures botan's different SHA1 providers, instead of
19// only measuring one.
20#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,23)
21 #include <botan/libstate.h>
22 #include <botan/benchmark.h>
23#endif
24
25#include "sanity.hh"
26#include "ui.hh"
27#include "platform.hh"
28#include "cmd.hh"
29#include "transforms.hh"
30
31using std::string;
32
33CMD_HIDDEN(benchmark_sha1, "benchmark_sha1", "", CMD_REF(debug), "",
34 N_("Benchmarks botan's SHA-1 core"),
35 "",
36 options::opts::none)
37{
38 P(F("Benchmarking botan's SHA-1 core"));
39
40#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,23)
41
42 Botan::AutoSeeded_RNG rng;
43 Botan::Algorithm_Factory& af =
44 Botan::global_state().algorithm_factory();
45
46 const int milliseconds = 5000;
47
48 // timer argument was removed in 1.9.4
49#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,9,4)
50 Botan::Default_Benchmark_Timer timer;
51 std::map<std::string, double> results =
52 Botan::algorithm_benchmark("SHA-1", milliseconds, timer, rng, af);
53#elif BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,9,11)
54 std::map<std::string, double> results =
55 Botan::algorithm_benchmark("SHA-1", milliseconds, rng, af);
56#else
57 std::map<std::string, double> results =
58 Botan::algorithm_benchmark("SHA-1", af, rng, milliseconds, 16);
59#endif
60
61 for(std::map<std::string, double>::const_iterator i = results.begin();
62 i != results.end(); ++i)
63 {
64 P(F("SHA-1 provider '%s': %s MiB/s") % i->first % i->second);
65 }
66
67#else
68 int mebibytes = 100;
69 string test_str(mebibytes << 20, 'a');
70 data test_data(test_str, origin::internal);
71 id foo;
72 double start = cpu_now();
73 calculate_ident(test_data, foo);
74 double end = cpu_now();
75 double mebibytes_per_sec = mebibytes / (end - start);
76 P(F("%s MiB/s") % mebibytes_per_sec);
77#endif
78}
79
80// Local Variables:
81// mode: C++
82// fill-column: 76
83// c-file-style: "gnu"
84// indent-tabs-mode: nil
85// End:
86// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status