c++ - How can I make my own timer without standard library? -


is there specific number of iterations, make using for loop, takes 1 second loop executed completely? example following code took 0.125s on machine execute:

#include <iostream> #include <cmath>  using namespace  std;  int main(){     long long a=0;      (a=0;a<=pow(10,4);a++); } 

though, <= 8*pow(10,4) took 0.206 s. compiler gcc 4.9.2. ide codeblocks.

my pc's specs: os: windows 8.1 enter image description here

i posting answer question, per comments received.

it not possible make timer because:

  • the time iteration take unpredictable, depends not on cpu used, need take account power management, scheduler. (by tux3)
  • one have use real time os accomplish that. there's jitter in non realtime oss. windows decide schedule other processes while, or use cpu e.g. kernel networking, disk i/o etc. preempts timing. (by nos)

  • one can't "make own timer" in hosted environment in standard c++. timer mechanism communicate os scheduler, , 1 needs platform-specific os services that. (by kerrek sb)

  • the compiler optimize such loop , remove through dead-code elimination (by πάντα ῥεῖ , jongware).


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -