WeiqiShi | a79c778 | 2014-12-26 09:42:10 +0800 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014, Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of NDN repo-ng (Next generation of NDN repository). |
| 6 | * See AUTHORS.md for complete list of repo-ng authors and contributors. |
| 7 | * |
| 8 | * repo-ng is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include "skiplist-list.hpp" // This skiplist is updated by weiqi. |
| 21 | // The internal structure of skiplist node is std::list |
| 22 | |
| 23 | #include "skiplist-vector.hpp" // This skiplist is revised is revised based on the version above |
| 24 | // The internal structure of skiplist node is std::vector |
| 25 | |
| 26 | #include "skiplist-prev.hpp" // This skiplist is that of previous commit |
| 27 | |
| 28 | #include <iostream> |
| 29 | #include <set> |
| 30 | |
| 31 | using namespace ndn::time; |
| 32 | |
| 33 | namespace repo { |
| 34 | namespace tests { |
| 35 | |
| 36 | void |
| 37 | testSkipList() |
| 38 | { |
| 39 | typedef update1::SkipList<int, std::greater<int> > IntGtContainer; |
| 40 | IntGtContainer sl; |
| 41 | steady_clock::TimePoint start = steady_clock::now(); |
| 42 | for (int i = 0; i < 100000; ++i) { |
| 43 | sl.insert(i); |
| 44 | } |
| 45 | milliseconds duration = duration_cast<milliseconds>(steady_clock::now() - start); |
| 46 | start = steady_clock::now(); |
| 47 | std::cout << "SkipList-list insert 100000 integers cost " << duration.count() << "ms" << std::endl; |
| 48 | for (int i = 0; i< 100000; ++i) { |
| 49 | sl.lower_bound(i); |
| 50 | } |
| 51 | duration = duration_cast<milliseconds>(steady_clock::now() - start); |
| 52 | std::cout << "SkipList-list lower_bound 100000 integers cost " << duration.count() << "ms" << std::endl; |
| 53 | } |
| 54 | |
| 55 | void |
| 56 | testSkipVector() |
| 57 | { |
| 58 | typedef update2::SkipList<int, std::greater<int> > IntGtContainer; |
| 59 | IntGtContainer container; |
| 60 | steady_clock::TimePoint start = steady_clock::now(); |
| 61 | for (int i = 0; i < 100000; ++i) { |
| 62 | container.insert(i); |
| 63 | } |
| 64 | milliseconds duration = duration_cast<milliseconds>(steady_clock::now() - start); |
| 65 | start = steady_clock::now(); |
| 66 | std::cout << "Skiplist-vector insert 100000 integers cost " << duration.count() << "ms" << std::endl; |
| 67 | for (int i = 0; i< 100000; ++i) { |
| 68 | container.lower_bound(i); |
| 69 | } |
| 70 | duration = duration_cast<milliseconds>(steady_clock::now() - start); |
| 71 | std::cout << "Skiplist-vector lower_bound 100000 integers cost " << duration.count() << "ms" << std::endl; |
| 72 | } |
| 73 | |
| 74 | void |
| 75 | testSkipPrev() |
| 76 | { |
| 77 | typedef prev::SkipList<int, std::greater<int> > IntGtContainer; |
| 78 | IntGtContainer container; |
| 79 | steady_clock::TimePoint start = steady_clock::now(); |
| 80 | for (int i = 0; i < 100000; ++i) { |
| 81 | container.insert(i); |
| 82 | } |
| 83 | milliseconds duration = duration_cast<milliseconds>(steady_clock::now() - start); |
| 84 | start = steady_clock::now(); |
| 85 | std::cout << "Skiplist-prev insert 100000 integers cost " << duration.count() << "ms" << std::endl; |
| 86 | for (int i = 0; i< 100000; ++i) { |
| 87 | container.lower_bound(i); |
| 88 | } |
| 89 | duration = duration_cast<milliseconds>(steady_clock::now() - start); |
| 90 | std::cout << "Skiplist-prev lower_bound 100000 integers cost " << duration.count() << "ms" << std::endl; |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | testSet() |
| 95 | { |
| 96 | typedef std::set<int, std::greater<int> > IntGtContainer; |
| 97 | IntGtContainer container; |
| 98 | steady_clock::TimePoint start = steady_clock::now(); |
| 99 | for (int i = 0; i < 100000; ++i) { |
| 100 | container.insert(i); |
| 101 | } |
| 102 | milliseconds duration = duration_cast<milliseconds>(steady_clock::now() - start); |
| 103 | start = steady_clock::now(); |
| 104 | std::cout << "Set insert 100000 integers cost " << duration.count() << "ms" << std::endl; |
| 105 | for (int i = 0; i< 100000; ++i) { |
| 106 | container.lower_bound(i); |
| 107 | } |
| 108 | duration = duration_cast<milliseconds>(steady_clock::now() - start); |
| 109 | std::cout << "Set lower_bound 100000 integers cost " << duration.count() << "ms" << std::endl; |
| 110 | } |
| 111 | |
| 112 | void runTestCases() { |
| 113 | testSkipList(); |
| 114 | testSkipVector(); |
| 115 | testSkipPrev(); |
| 116 | testSet(); |
| 117 | } |
| 118 | |
| 119 | } // namespace tests |
| 120 | } // namespace repo |
| 121 | |
| 122 | int |
| 123 | main(int argc, char** argv) |
| 124 | { |
| 125 | repo::tests::runTestCases(); |
| 126 | |
| 127 | return 0; |
| 128 | } |