Home » Developing U++ » Bugs (& fixes) » A strange bug in std::chrono
A strange bug in std::chrono [message #57440] |
Fri, 13 August 2021 03:16 |
chivstyle
Messages: 8 Registered: August 2020 Location: China
|
Promising Member |
|
|
upp:15935
os: Windows 10 64 bits, ver: 10.0.19042.985
I used std::chrono::high_resolution_clock to calculate time interval, like below:
double ts = 0;
auto t1 = std::chrono::high_resolution_clock::now();
do_something();
auto t2 = std::chrono::high_resolution_clock::now();
ts += std::chrono::duration<double>(t2 - t1).count();
The value of ts will be minus. I attached an example to demonstrate this bug, please check it out.
(complie it: clang++ -o chrono_test chrono_test.cpp)
If it catched this bug, the app will exit at once.
q_count = 1101145088, q_rate = 799.75
q_count = 1101146112, q_rate = 799.75
q_count = 1101147136, q_rate = 799.75
q_count = 1101148160, q_rate = 799.75
q_count = 1101149184, q_rate = 799.75
q_count = 1101150208, q_rate = 799.75
q_count = 1101151232, q_rate = 799.75
q_count = 1101152256, q_rate = 799.75
q_count = 1101153280, q_rate = -2150.39
catched that bug, hahaha
Of course, I compiled this program with gcc, and clang from latest msys2. It worked well. So I think it's a bug.
|
|
|
|
Goto Forum:
Current Time: Thu Nov 14 05:03:56 CET 2024
Total time taken to generate the page: 0.02736 seconds
|