Project

General

Profile

Bug #1589 ยป sign-bench.cpp

KeyChain::sign benchmark tool - Junxiao Shi, 05/10/2014 11:29 PM

 
1
// ndn-cxx KeyChain::sign benchmark tool
2
//
3
// Compile with:
4
// (OSX only) export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
5
// g++ -o sign-bench sign-bench.cpp `pkg-config --libs --cflags libndn-cxx`
6
//
7
// HOW TO USE
8
// 1. edit ~/.ndn/client.conf to choose between file or osx-keychain TPM
9
//    (osx-keychain TPM is available on GUI mode only)
10
// 2. install a default certificate
11
//    (after choosing correct TPM)
12
// 3. run this benchmark
13
//    If "sign-bench wants to sign using key" popup appears, click [Always Allow],
14
//    and rerun the benchmark.
15

    
16
#include <ndn-cxx/security/key-chain.hpp>
17

    
18
using namespace ndn;
19

    
20
int
21
main(int argc, char** argv)
22
{
23
  if (argc != 2) {
24
    std::cout << "sign-bench iterations" << std::endl;
25
    return 1;
26
  }
27
  int nIterations = atoi(argv[1]);
28
  
29
  static const size_t PAYLOAD_SIZE = 4096;
30
  uint8_t content[PAYLOAD_SIZE];
31
  Data data("ndn:/");
32
  data.setContent(content, sizeof(content));
33
  
34
  KeyChain keyChain;
35

    
36
  time::steady_clock::TimePoint t1 = time::steady_clock::now();
37
  
38
  for (int i = 0; i < nIterations; ++i) {
39
    keyChain.sign(data);
40
  }
41
  
42
  time::steady_clock::TimePoint t2 = time::steady_clock::now();
43
  
44
  std::cout << "KeyChain::sign payloadSize=" << PAYLOAD_SIZE
45
            << " nIterations=" << nIterations
46
            << " duration=" << time::duration_cast<time::milliseconds>(t2 - t1)
47
            << std::endl;
48
  
49
  return 0;
50
}
51

    
    (1-1/1)