Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I adjust the accuracy of timer? #295

Open
zhmt opened this issue Apr 7, 2022 · 0 comments
Open

Can I adjust the accuracy of timer? #295

zhmt opened this issue Apr 7, 2022 · 0 comments

Comments

@zhmt
Copy link

zhmt commented Apr 7, 2022

Failed to achieve FPS 60 ( frame per second) :

auto timenow() {
  return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}

int main() {
  boost::fibers::fiber mainFiber([]() 
    {
      while (true) {
        auto now = timenow();
        boost::this_fiber::sleep_for(std::chrono::milliseconds(16));
        std::cout << timenow() - now << "\n";
      }
    });
  mainFiber.join();
}

Outputs ( should be 16 ):

34
27
30
31
31
31
30
31
30
29
@zhmt zhmt changed the title Can I ajust the accuracy of timer? Can I adjust the accuracy of timer? Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant