blob: 415d03dd7f8c21679fc25ed59290f5648e7faed7 [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"
Alexander Afanasyev4a771362014-04-24 21:29:33 -070027#include <ndn-cxx/security/key-chain.hpp>
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040028
29namespace nfd {
Junxiao Shi2e0db682014-11-27 21:22:27 -070030namespace cs_smoketest {
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040031
32static void
33runStressTest()
34{
35 shared_ptr<Data> dataWorkload[70000];
36 shared_ptr<Interest> interestWorkload[70000];
37
38 ndn::SignatureSha256WithRsa fakeSignature;
39 fakeSignature.setValue(ndn::dataBlock(tlv::SignatureValue,
40 reinterpret_cast<const uint8_t*>(0), 0));
41
42 // 182 MB in memory
Junxiao Shi2e0db682014-11-27 21:22:27 -070043 for (int i = 0; i < 70000; i++) {
44 Name name("/stress/test");
45 name.appendNumber(i % 4);
46 name.appendNumber(i);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040047
Junxiao Shi2e0db682014-11-27 21:22:27 -070048 shared_ptr<Interest> interest = make_shared<Interest>(name);
49 interestWorkload[i] = interest;
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040050
Junxiao Shi2e0db682014-11-27 21:22:27 -070051 shared_ptr<Data> data = make_shared<Data>(name);
52 data->setSignature(fakeSignature);
53 dataWorkload[i] = data;
54 }
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040055
56 time::duration<double, boost::nano> previousResult(0);
57
Junxiao Shi2e0db682014-11-27 21:22:27 -070058 for (size_t nInsertions = 1000; nInsertions < 10000000; nInsertions *= 2) {
59 Cs cs;
60 srand(time::toUnixTimestamp(time::system_clock::now()).count());
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040061
Junxiao Shi2e0db682014-11-27 21:22:27 -070062 time::steady_clock::TimePoint startTime = time::steady_clock::now();
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040063
Junxiao Shi2e0db682014-11-27 21:22:27 -070064 size_t workloadCounter = 0;
65 for (size_t i = 0; i < nInsertions; i++) {
66 if (workloadCounter > 69999)
67 workloadCounter = 0;
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040068
Junxiao Shi2e0db682014-11-27 21:22:27 -070069 cs.find(*interestWorkload[workloadCounter]);
70 Data& data = *dataWorkload[workloadCounter];
71 data.setName(data.getName()); // reset data.m_fullName
72 data.wireEncode();
73 cs.insert(data);
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040074
Junxiao Shi2e0db682014-11-27 21:22:27 -070075 workloadCounter++;
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040076 }
Junxiao Shi2e0db682014-11-27 21:22:27 -070077
78 time::steady_clock::TimePoint endTime = time::steady_clock::now();
79
80 time::duration<double, boost::nano> runDuration = endTime - startTime;
81 time::duration<double, boost::nano> perOperationTime = runDuration / nInsertions;
82
83 std::cout << "nItem = " << nInsertions << std::endl;
84 std::cout << "Total running time = "
85 << time::duration_cast<time::duration<double> >(runDuration)
86 << std::endl;
87 std::cout << "Average per-operation time = "
88 << time::duration_cast<time::duration<double, boost::micro> >(perOperationTime)
89 << std::endl;
90
91 if (previousResult > time::nanoseconds(1))
92 std::cout << "Change compared to the previous: "
93 << (100.0 * perOperationTime / previousResult) << "%" << std::endl;
94
95 std::cout << "\n=================================\n" << std::endl;
96
97 previousResult = perOperationTime;
98 }
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -040099}
100
Junxiao Shi2e0db682014-11-27 21:22:27 -0700101} // namespace cs_smoketest
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400102} // namespace nfd
103
104int
105main(int argc, char** argv)
106{
Junxiao Shi2e0db682014-11-27 21:22:27 -0700107 nfd::cs_smoketest::runStressTest();
Ilya Moiseenko96b80bb2014-04-05 20:53:27 -0400108
109 return 0;
110}