🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.c
Article #308973

Re: Milisekundy i mikrosekundy do logu

#308973
From: bartekltg
Date: Mon, 16 Jan 2017 13:00
111 lines
2438 bytes
On 14.01.2017 18:11, Borneq wrote:

> Do logu wypisuję czas, chciałbym mieć dokładność lepsza niż sekunda
> zarówno pod Windows jak i Linuxa


Użyj c++ ;-)

#include <vector>
#include <chrono>

int main(int argc, char *argv[])
{


     auto start= std::chrono::high_resolution_clock::now();

     vector <decltype( start)> stop;

     for (int i=0;i<30;i++)
         stop.push_back (std::chrono::high_resolution_clock::now());

     for (auto s : stop)
         std::cout << 
std::chrono::duration_cast<std::chrono::nanoseconds>(s-start).count() << 
"ns" << std::endl;

}




Wyniki (linux)


    489
     3422
     7822
     8311
     9289
    10267
    10755
    11244
    12222
    13200
    13689
    14667
    15155
    15644
    16622
    17111
    18089
    19067
    20044
    20533
    21511
    22000
    22489
    23467
    23955
    24933
    25422
    26400
    26889
    27867


Robimy diffa:


    2933
    4400
     489
     978
     978
     488
     489
     978
     978
     489
     978
     488
     489
     978
     489
     978
     978
     977
     489
     978
     489
     489
     978
     488
     978
     489
     978
     489
     978


Wygląda, że tyka co mniej niż 1 us.

To powinien być zegar o najmniejszym okresie dostępny na kompie.
Być mozę do niektórych zastosowań lepszy bedzie steady_clock.
Godzin,ę wyciagasz tak
http://en.cppreference.com/w/cpp/chrono/time_point/time_since_epoch


pzdr
bartekltg
Technical Details
Message-ID: <o5ig5l$v5b$1@node1.news.atman.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
References: <o5dm4s$tln$1@node2.news.atman.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail
From: bartekltg <bartekltg@gmail.com>
Newsgroups: pl.comp.lang.c
Subject: Re: Milisekundy i mikrosekundy do logu
Date: Mon, 16 Jan 2017 14:00:36 +0100
Organization: ATMAN - ATM S.A.
Lines: 115
Message-ID: <o5ig5l$v5b$1@node1.news.atman.pl>
References: <o5dm4s$tln$1@node2.news.atman.pl>
NNTP-Posting-Host: 89-70-119-159.dynamic.chello.pl
Mime-Version: 1.0
X-Trace: node1.news.atman.pl 1484571637 31915 89.70.119.159 (16 Jan 2017 13:00:37 GMT)
X-Complaints-To: usenet@atman.pl
NNTP-Posting-Date: Mon, 16 Jan 2017 13:00:37 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1
In-Reply-To: <o5dm4s$tln$1@node2.news.atman.pl>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit