diff --git a/TinySTL/Profiler/Profiler.cpp b/TinySTL/Profiler/Profiler.cpp new file mode 100644 index 0000000..74e2a72 --- /dev/null +++ b/TinySTL/Profiler/Profiler.cpp @@ -0,0 +1,22 @@ +#include "Profiler.h" + +namespace TinySTL{ + namespace Profiler{ + + ProfilerInstance::TimePoint ProfilerInstance::startTime; + ProfilerInstance::TimePoint ProfilerInstance::finishTime; + + void ProfilerInstance::start(){ + startTime = SteadyClock::now(); + } + void ProfilerInstance::finish(){ + finishTime = SteadyClock::now(); + } + 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; + } + } +} \ No newline at end of file diff --git a/TinySTL/Profiler/Profiler.h b/TinySTL/Profiler/Profiler.h new file mode 100644 index 0000000..f9333bb --- /dev/null +++ b/TinySTL/Profiler/Profiler.h @@ -0,0 +1,29 @@ +#ifndef _PROFILER_H_ +#define _PROFILER_H_ + +#include +#include +#include +#include +#include +#include + +namespace TinySTL{ + namespace Profiler{ + + class ProfilerInstance{ + public: + typedef std::chrono::steady_clock SteadyClock; + typedef SteadyClock::time_point TimePoint; + private: + static TimePoint startTime; + static TimePoint finishTime; + public: + static void start(); + static void finish(); + static void dumpDuringTime(std::ostream& os = std::cout); + }; + } +} + +#endif \ No newline at end of file diff --git a/TinySTL/main.cpp b/TinySTL/main.cpp index e138036..fbb7869 100644 --- a/TinySTL/main.cpp +++ b/TinySTL/main.cpp @@ -7,18 +7,26 @@ #include "Allocator.h" #include "Construct.h" #include "Vector.h" +#include "Profiler\Profiler.h" #include "UninitializedFunctions.h" using namespace std; +using namespace TinySTL::Profiler; int main(){ - int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - //TinySTL::vector svec(array, array + 5); - //svec.erase(svec.begin() + 1, svec.begin() + 4);//1,5 - TinySTL::vector svec(10, 0); - svec.insert(svec.begin() + 0, array, array + 10); - //svec.insert(svec.begin()+0, 10, 99); - for (auto s : svec){ cout << s << endl; } + + int array[100000] = { 1 }; + std::vector vec; + //TinySTL::vector vec; + ProfilerInstance::start(); + int i = 0; + for (; i != 10000000; ++i){ + //vec.insert(vec.end(), array, array + 1); + vec.push_back(i); + } + //vec.insert(vec.end(), array, array + 100000); + ProfilerInstance::finish(); + ProfilerInstance::dumpDuringTime(); system("pause"); return 0; }