File: sha1.cc

package info (click to toggle)
monotone 0.48-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 20,096 kB
  • ctags: 8,077
  • sloc: cpp: 81,000; sh: 6,402; perl: 1,241; lisp: 1,045; makefile: 655; python: 566; sql: 112; ansic: 52
file content (83 lines) | stat: -rw-r--r-- 2,394 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (C) 2006 Nathaniel Smith <njs@pobox.com>
//
// This program is made available under the GNU GPL version 2.0 or
// greater. See the accompanying file COPYING for details.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE.

// This file holds a registry of different SHA-1 implementations, and lets us
// benchmark them.

#include "base.hh"
#include <botan/botan.h>
#include <botan/sha160.h>

// Botan 1.7.23+ and 1.8.x specific sha1 benchmarking code uses botan's
// own timer and measures botan's different SHA1 providers, instead of
// only measuring one.
#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,23)
  #include <botan/libstate.h>
  #include <botan/benchmark.h>
#endif

#include "sanity.hh"
#include "ui.hh"
#include "platform.hh"
#include "cmd.hh"
#include "transforms.hh"

using std::string;

CMD_HIDDEN(benchmark_sha1, "benchmark_sha1", "", CMD_REF(debug), "",
           N_("Benchmarks botan's SHA-1 core"),
           "",
           options::opts::none)
{
  P(F("Benchmarking botan's SHA-1 core"));

#if BOTAN_VERSION_CODE >= BOTAN_VERSION_CODE_FOR(1,7,23)

  Botan::AutoSeeded_RNG rng;
  Botan::Algorithm_Factory& af =
    Botan::global_state().algorithm_factory();

  const int milliseconds = 5000;

  // timer argument was removed in 1.9.4
#if BOTAN_VERSION_CODE < BOTAN_VERSION_CODE_FOR(1,9,4)
  Botan::Default_Benchmark_Timer timer;
  std::map<std::string, double> results =
    Botan::algorithm_benchmark("SHA-1",  milliseconds, timer, rng, af);
#else
  std::map<std::string, double> results =
    Botan::algorithm_benchmark("SHA-1",  milliseconds, rng, af);
#endif

  for(std::map<std::string, double>::const_iterator i = results.begin();
      i != results.end(); ++i)
    {
      P(F("SHA-1 provider '%s': %s MiB/s") % i->first % i->second);
    }

#else
  int mebibytes = 100;
  string test_str(mebibytes << 20, 'a');
  data test_data(test_str, origin::internal);
  id foo;
  double start = cpu_now();
  calculate_ident(test_data, foo);
  double end = cpu_now();
  double mebibytes_per_sec = mebibytes / (end - start);
  P(F("%s MiB/s") % mebibytes_per_sec);
#endif
}

// Local Variables:
// mode: C++
// fill-column: 76
// c-file-style: "gnu"
// indent-tabs-mode: nil
// End:
// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s: