Skip to content

File structs.h

File List > extra > structs.h

Go to the documentation of this file

#pragma once

#include <string>
#include <vector>
#include <ctime>
#include <iostream>

struct Timer
{
    time_t start = 0;        
    time_t end = 0;          
    time_t tick = 0;         
    time_t temp = 0;         
    time_t __duration = 0;   
    int fact = 1;            
    std::string name;        
    bool is_print;           

    Timer(std::string name="Thread", int fact = 1, bool print = true) 
        :name(name), fact(fact), is_print(print)
    {
#ifdef _DEBUG
        if (is_print)
            std::cout << "[ " + name + " Start ]\n";
#endif // _DEBUG
        start = tick = temp = clock();
    }

    time_t Tick() {
        /*std::cout << 000000 << "\n";*/
        tick = clock();
        __duration = tick - temp;
        temp = tick;
#ifdef _DEBUG
        if (is_print)
            std::cout /*<< "\r"*/ << "[ duration = " << __duration * fact << "ms ]\n";
#endif // _DEBUG
        return __duration;
    }

    time_t GetDuration() {
        end = clock();
#ifdef _DEBUG
        if (is_print)
            std::cout /*<< "\r"*/ << "[ " + name + " Whole Time = " << (end - start) * fact << "ms ]\n";
#endif // _DEBUG
        return (end - start);
    }

    ~Timer() {
        end = clock();
        __duration = end - start;
#ifdef _DEBUG
        if (is_print)
            std::cout /*<< "\r"*/ << "[ "+name+" Whole Time = " << __duration * fact << "ms ]\n";
#endif // _DEBUG
    }
};

template<int _L>
struct AverageTime
{
    float result = 0; 

    void Update(float _rate) {
        result += (_rate - result) / _L;
    }
};