blob: be8973f340564813fa4d66ef13fbdaf48821ed54 [file] [log] [blame]
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology
9 *
10 * This file is part of NFD (Named Data Networking Forwarding Daemon).
11 * See AUTHORS.md for complete list of NFD authors and contributors.
12 *
13 * NFD is free software: you can redistribute it and/or modify it under the terms
14 * of the GNU General Public License as published by the Free Software Foundation,
15 * either version 3 of the License, or (at your option) any later version.
16 *
17 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
18 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
19 * PURPOSE. See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along with
22 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * \author Ilya Moiseenko <iliamo@ucla.edu>
25 **/
26
27#include "table/cs.hpp"
28#include "table/cs-entry.hpp"
29#include <ndn-cpp-dev/security/key-chain.hpp>
30
31namespace nfd {
32
33static void
34runStressTest()
35{
36 shared_ptr<Data> dataWorkload[70000];
37 shared_ptr<Interest> interestWorkload[70000];
38
39 ndn::SignatureSha256WithRsa fakeSignature;
40 fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue,
41 reinterpret_cast<const uint8_t*>(0), 0));
42
43 // 182 MB in memory
44 for (int i = 0; i < 70000; i++)
45 {
46 Name name("/stress/test");
47 name.appendNumber(i % 4);
48 name.appendNumber(i);
49
50 shared_ptr<Interest> interest = make_shared<Interest>(name);
51 interestWorkload[i] = interest;
52
53 shared_ptr<Data> data = make_shared<Data>(name);
54 data->setSignature(fakeSignature);
55 dataWorkload[i] = data;
56 }
57
58 time::duration<double, boost::nano> previousResult(0);
59
60 for (size_t nInsertions = 1000; nInsertions < 10000000; nInsertions *= 2)
61 {
62 Cs cs;
63 srand(time::toUnixTimestamp(time::system_clock::now()).count());
64
65 time::steady_clock::TimePoint startTime = time::steady_clock::now();
66
67 int workloadCounter = 0;
68 for (int i = 0; i < nInsertions; i++)
69 {
70 if (workloadCounter > 69999)
71 workloadCounter = 0;
72
73 cs.find(*interestWorkload[workloadCounter]);
74 cs.insert(*dataWorkload[workloadCounter]);
75
76 workloadCounter++;
77 }
78
79 time::steady_clock::TimePoint endTime = time::steady_clock::now();
80
81 time::duration<double, boost::nano> runDuration = endTime - startTime;
82 time::duration<double, boost::nano> perOperationTime = runDuration / nInsertions;
83
84 std::cout << "nItem = " << nInsertions << std::endl;
85 std::cout << "Total running time = "
86 << time::duration_cast<time::duration<double> >(runDuration)
87 << std::endl;
88 std::cout << "Average per-operation time = "
89 << time::duration_cast<time::duration<double, boost::micro> >(perOperationTime)
90 << std::endl;
91
92 if (previousResult > time::nanoseconds(1))
93 std::cout << "Change compared to the previous: "
94 << (100.0 * perOperationTime / previousResult) << "%" << std::endl;
95
96 std::cout << "\n=================================\n" << std::endl;
97
98 previousResult = perOperationTime;
99 }
100}
101
102} // namespace nfd
103
104int
105main(int argc, char** argv)
106{
107 nfd::runStressTest();
108
109 return 0;
110}