From 3dc37301672cc197c8bf578af7bcc808561a208a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=93=E8=88=AA?= <1210603696@qq.com> Date: Sat, 18 Oct 2014 12:31:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9ProfilerInstance=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BD=BF=E5=85=B6=E6=9B=B4=E5=8F=8B=E5=A5=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TinySTL/Profiler/Profiler.cpp | 11 +++++--- TinySTL/Profiler/Profiler.h | 5 ++++ TinySTL/main.cpp | 47 +++++++++++++++++++---------------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/TinySTL/Profiler/Profiler.cpp b/TinySTL/Profiler/Profiler.cpp index 74e2a72..4f9a70a 100644 --- a/TinySTL/Profiler/Profiler.cpp +++ b/TinySTL/Profiler/Profiler.cpp @@ -5,18 +5,23 @@ namespace TinySTL{ ProfilerInstance::TimePoint ProfilerInstance::startTime; ProfilerInstance::TimePoint ProfilerInstance::finishTime; + ProfilerInstance::DurationTime ProfilerInstance::duringTime; void ProfilerInstance::start(){ startTime = SteadyClock::now(); } void ProfilerInstance::finish(){ finishTime = SteadyClock::now(); + duringTime = std::chrono::duration_cast(finishTime - startTime); } void ProfilerInstance::dumpDuringTime(std::ostream& os){ - typedef std::chrono::duration DurationTime; - DurationTime duringTime = - std::chrono::duration_cast(finishTime - startTime); os << "total " << duringTime.count() * 1000 << " milliseconds" << std::endl; } + double ProfilerInstance::second(){ + return duringTime.count(); + } + double ProfilerInstance::millisecond(){ + return duringTime.count() * 1000; + } } } \ No newline at end of file diff --git a/TinySTL/Profiler/Profiler.h b/TinySTL/Profiler/Profiler.h index f9333bb..1656eb6 100644 --- a/TinySTL/Profiler/Profiler.h +++ b/TinySTL/Profiler/Profiler.h @@ -15,13 +15,18 @@ namespace TinySTL{ public: typedef std::chrono::steady_clock SteadyClock; typedef SteadyClock::time_point TimePoint; + typedef std::chrono::duration DurationTime; private: + static DurationTime duringTime; static TimePoint startTime; static TimePoint finishTime; public: static void start(); static void finish(); static void dumpDuringTime(std::ostream& os = std::cout); + + static double second(); + static double millisecond(); }; } } diff --git a/TinySTL/main.cpp b/TinySTL/main.cpp index c2fc2d8..935de43 100644 --- a/TinySTL/main.cpp +++ b/TinySTL/main.cpp @@ -1,5 +1,7 @@ #include +#include #include +#include #include #include #include @@ -7,6 +9,8 @@ #include #include #include +#include +#include #include #include @@ -17,31 +21,32 @@ #include "Vector.h" #include "Profiler\Profiler.h" +#include "BinarySearchTree.h" +#include "CircularBuffer.h" +#include "Deque.h" #include "Queue.h" +#include "Stack.h" +using namespace std; using namespace TinySTL::Profiler; -class mycomparison -{ - bool reverse; -public: - mycomparison(const bool& revparam = false) - { - reverse = revparam; - } - bool operator() (const int& lhs, const int&rhs) const - { - if (reverse) return (lhs>rhs); - else return (lhs myvector(array, array+5); - std::cout << "myvector backwards:"; - for (auto rit = myvector.crbegin(); rit != myvector.crend(); ++rit) - std::cout << ' ' << *rit; - std::cout << '\n'; +int main(){ + //TinySTL::deque dq; + //int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; + int array[] = { 5, 3, 2, 7, 6, 8, 8 }; + TinySTL::binary_search_tree bst; + bst.insert(array, array + 7); + //std::vector vec; + TinySTL::vector vec; + ProfilerInstance::start(); + int i = 0; + for (; i != 1000000; ++i){ + vec.push_back(i); + } + ProfilerInstance::finish(); + ProfilerInstance::dumpDuringTime(); + cout << ProfilerInstance::millisecond() << endl; + system("pause"); return 0; }