blob: 1fc97c90c9826b1557b0f0786b95200528da116a [file] [log] [blame]
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi2e0db682014-11-27 21:22:27 -07003 * 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 * The University of Memphis
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Junxiao Shi2e0db682014-11-27 21:22:27 -070024 */
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040025
26#include "table/cs.hpp"
27#include "table/cs-entry.hpp"
Alexander Afanasyev4a771362014-04-24 21:29:33 -070028#include <ndn-cxx/security/key-chain.hpp>
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040029
30namespace nfd {
Junxiao Shi2e0db682014-11-27 21:22:27 -070031namespace cs_smoketest {
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040032
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
Junxiao Shi2e0db682014-11-27 21:22:27 -070044 for (int i = 0; i < 70000; i++) {
45 Name name("/stress/test");
46 name.appendNumber(i % 4);
47 name.appendNumber(i);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040048
Junxiao Shi2e0db682014-11-27 21:22:27 -070049 shared_ptr<Interest> interest = make_shared<Interest>(name);
50 interestWorkload[i] = interest;
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040051
Junxiao Shi2e0db682014-11-27 21:22:27 -070052 shared_ptr<Data> data = make_shared<Data>(name);
53 data->setSignature(fakeSignature);
54 dataWorkload[i] = data;
55 }
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040056
57 time::duration<double, boost::nano> previousResult(0);
58
Junxiao Shi2e0db682014-11-27 21:22:27 -070059 for (size_t nInsertions = 1000; nInsertions < 10000000; nInsertions *= 2) {
60 Cs cs;
61 srand(time::toUnixTimestamp(time::system_clock::now()).count());
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040062
Junxiao Shi2e0db682014-11-27 21:22:27 -070063 time::steady_clock::TimePoint startTime = time::steady_clock::now();
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040064
Junxiao Shi2e0db682014-11-27 21:22:27 -070065 size_t workloadCounter = 0;
66 for (size_t i = 0; i < nInsertions; i++) {
67 if (workloadCounter > 69999)
68 workloadCounter = 0;
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040069
Junxiao Shi2e0db682014-11-27 21:22:27 -070070 cs.find(*interestWorkload[workloadCounter]);
71 Data& data = *dataWorkload[workloadCounter];
72 data.setName(data.getName()); // reset data.m_fullName
73 data.wireEncode();
74 cs.insert(data);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040075
Junxiao Shi2e0db682014-11-27 21:22:27 -070076 workloadCounter++;
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040077 }
Junxiao Shi2e0db682014-11-27 21:22:27 -070078
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 }
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400100}
101
Junxiao Shi2e0db682014-11-27 21:22:27 -0700102} // namespace cs_smoketest
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400103} // namespace nfd
104
105int
106main(int argc, char** argv)
107{
Junxiao Shi2e0db682014-11-27 21:22:27 -0700108 nfd::cs_smoketest::runStressTest();
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400109
110 return 0;
111}