C++ Cross-Platform High-Resolution Timer

前端 未结 14 2151
不知归路
不知归路 2020-11-22 12:45

I\'m looking to implement a simple timer mechanism in C++. The code should work in Windows and Linux. The resolution should be as precise as possible (at least millisecond a

14条回答
  •  长情又很酷
    2020-11-22 13:52

    I have seen this implemented a few times as closed-source in-house solutions .... which all resorted to #ifdef solutions around native Windows hi-res timers on the one hand and Linux kernel timers using struct timeval (see man timeradd) on the other hand.

    You can abstract this and a few Open Source projects have done it -- the last one I looked at was the CoinOR class CoinTimer but there are surely more of them.

提交回复
热议问题