mardi 3 décembre 2019

Wrong chrono.count() output when measure time

I'm trying to store the time actual now_time_point intro a variable, wait a while and compare now_time_point with actual_time_point and get the elapsed seconds..

Ex: Passed seconds since now_time_point to actual_time_point

.cpp file

#include "FFOO.hpp"

FFOO::FFOO()
{
    X = {};
}

FFOO::~FFOO()
{
    X = {};
}

std::int32_t FFOO::GetElapsed()
{
    return std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - Get()).count();
}

.h file

#pragma once
#include <chrono>

using time_point = std::chrono::steady_clock::time_point;

class FFOO
{
public:
    FFOO();
    virtual ~FFOO();

public:
    void Get(time_point arg) {X = arg;}
    time_point  Set() {return X;}

    std::int32_t GetElapsed();

protected:
    time_point  X;
};

What's the issue? I got an weird output like

54354372

Starting this time is gonna count corectly 54354372 .. 54354373 .. 54354374... Also i got an output even if i print GetElapsed without seting time using Set(), is right to get an output even if i not set the time with Set() ?

I want to work like that :

-Set()
-GetElapsed()
- Print: 1, 2,3 ,4 ... etc

What i do wrong?

Aucun commentaire:

Enregistrer un commentaire