Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #87275

Re: what is the best way to get microseconds of time on Windows in C or C++ ?

From Juha Nieminen <nospam@thanks.invalid>
Newsgroups comp.lang.c++
Subject Re: what is the best way to get microseconds of time on Windows in C or C++ ?
Date 2022-11-07 07:20 +0000
Organization Aioe.org NNTP Server
Message-ID <tkabkp$1bm8$2@gioia.aioe.org> (permalink)
References <tk1p0t$1iv03$1@dont-email.me> <41369206-19bc-4a68-8495-9af712215af8n@googlegroups.com>

Show all headers | View raw


Öö Tiib <ootiib@hot.ee> wrote:
> I have such code snippet copy-pasted from somewhere about portable
> since C++11.
> 
> auto t0 = std::chrono::high_resolution_clock::now();        
> auto nanosec = t0.time_since_epoch();
> 
> std::cout << nanosec.count() << " nanoseconds since epoch\n";
> std::cout << nanosec.count() / (1000000000.0 * 60.0 * 60.0) << " hours since epoch\n";
> 
> As I rarely need nanoseconds haven't tried it everywhere
> but at least looks portable.

I highly doubt that's going to return values at the nanosecond, or even
microsecond accuracy. (In other words, it's likely that the returned
value will jump by significantly more than a microsecond, at larger
time intervals, meaning that if you read the time again within that
time interval you'll just get the same value.)

Although, of course, this will depend on the target platform.
At a very minimum you can't assume the return value will have that
resolution.

(I don't know what guarantees the standard gives for this. Probably
none.)

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-03 20:14 -0500
  Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 00:06 -0500
    Re: what is the best way to get microseconds of time on Windows in C or C++ ? Christian Gollwitzer <auriocus@gmx.de> - 2022-11-04 08:03 +0100
      Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 14:32 -0500
    Re: what is the best way to get microseconds of time on Windows in C or C++ ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-11-04 09:07 -0700
      Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 14:33 -0500
    Re: what is the best way to get microseconds of time on Windows in C or C++ ? Opus <ifonly@youknew.org> - 2022-11-06 20:53 +0100
      Re: what is the best way to get microseconds of time on Windows in C or C++ ? Michael S <already5chosen@yahoo.com> - 2022-11-06 14:30 -0800
        Re: what is the best way to get microseconds of time on Windows in C or C++ ? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-11-07 07:48 +0100
          Re: what is the best way to get microseconds of time on Windows in C or C++ ? Michael S <already5chosen@yahoo.com> - 2022-11-07 04:11 -0800
            Re: what is the best way to get microseconds of time on Windows in C or C++ ? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-11-08 18:30 +0100
              Re: what is the best way to get microseconds of time on Windows in C or C++ ? Michael S <already5chosen@yahoo.com> - 2022-11-08 15:37 -0800
                Re: what is the best way to get microseconds of time on Windows in C or C++ ? Öö Tiib <ootiib@hot.ee> - 2022-11-09 06:14 -0800
                Re: what is the best way to get microseconds of time on Windows in C or C++ ? Michael S <already5chosen@yahoo.com> - 2022-11-12 16:21 -0800
  Re: what is the best way to get microseconds of time on Windows in C or C++ ? Juha Nieminen <nospam@thanks.invalid> - 2022-11-04 07:35 +0000
    Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 14:24 -0500
      Re: what is the best way to get microseconds of time on Windows in C or C++ ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-11-04 19:50 +0000
        Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 15:16 -0500
      Re: what is the best way to get microseconds of time on Windows in C or C++ ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-11-04 15:05 -0700
        Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 17:35 -0500
          Re: what is the best way to get microseconds of time on Windows in C or C++ ? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-11-04 15:56 -0700
          Re: what is the best way to get microseconds of time on Windows in C or C++ ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-11-04 16:15 -0700
          Re: what is the best way to get microseconds of time on Windows in C or C++ ? Michael S <already5chosen@yahoo.com> - 2022-11-06 14:41 -0800
            Re: what is the best way to get microseconds of time on Windows in C or C++ ? scott@slp53.sl.home (Scott Lurndal) - 2022-11-07 14:39 +0000
              Re: what is the best way to get microseconds of time on Windows in C or C++ ? Michael S <already5chosen@yahoo.com> - 2022-11-07 11:03 -0800
            Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-07 23:26 -0600
  Re: what is the best way to get microseconds of time on Windows in C or C++ ? Öö Tiib <ootiib@hot.ee> - 2022-11-04 01:23 -0700
    Re: what is the best way to get microseconds of time on Windows in C or C++ ? Juha Nieminen <nospam@thanks.invalid> - 2022-11-07 07:20 +0000
      Re: what is the best way to get microseconds of time on Windows in C or C++ ? Öö Tiib <ootiib@hot.ee> - 2022-11-07 07:11 -0800
  Re: what is the best way to get microseconds of time on Windows in C or C++ ? Michael S <already5chosen@yahoo.com> - 2022-11-04 03:12 -0700
    Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 14:35 -0500
  Re: what is the best way to get microseconds of time on Windows in C or C++ ? scott@slp53.sl.home (Scott Lurndal) - 2022-11-04 13:44 +0000
    Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-04 14:34 -0500
    Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-14 16:58 -0600
      Re: what is the best way to get microseconds of time on Windows in C or C++ ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-11-14 17:36 -0800
        Re: what is the best way to get microseconds of time on Windows in C or C++ ? Lynn McGuire <lynnmcguire5@gmail.com> - 2022-11-15 17:26 -0600
          Re: what is the best way to get microseconds of time on Windows in C or C++ ? Andreas <nospam@gmx.de> - 2022-11-16 13:15 +0100
  Re: what is the best way to get microseconds of time on Windows in C or C++ ? Bonita Montero <Bonita.Montero@gmail.com> - 2022-11-04 20:49 +0100
  Re: what is the best way to get microseconds of time on Windows in C or C++ ? Manu Raju <MR@invalid.invalid> - 2022-11-20 21:30 +0000

csiph-web