添加Profiler类
This commit is contained in:
22
TinySTL/Profiler/Profiler.cpp
Normal file
22
TinySTL/Profiler/Profiler.cpp
Normal file
@@ -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<double> DurationTime;
|
||||
DurationTime duringTime =
|
||||
std::chrono::duration_cast<DurationTime>(finishTime - startTime);
|
||||
os << "total " << duringTime.count() * 1000 << " milliseconds" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
29
TinySTL/Profiler/Profiler.h
Normal file
29
TinySTL/Profiler/Profiler.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef _PROFILER_H_
|
||||
#define _PROFILER_H_
|
||||
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <ratio>
|
||||
#include <utility>
|
||||
|
||||
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
|
||||
@@ -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<int> svec(array, array + 5);
|
||||
//svec.erase(svec.begin() + 1, svec.begin() + 4);//1,5
|
||||
TinySTL::vector<int> 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<int> vec;
|
||||
//TinySTL::vector<int> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user