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

Troubles with estimateClockResolution on Windows/GCC #1237

Closed
BynaryCobweb opened this Issue Apr 1, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@BynaryCobweb

BynaryCobweb commented Apr 1, 2018

Description

I encountered an issue while doing some benchmarking with Catch on Windows. When I try to execute my benchmark, the test program displays nothing and runs indefinitely, as if it was in an infinite loop.

Investigating a bit further, the problem have to do with estimateClockResolution() in catch_timer.cpp. This method takes a very, very, very long time to return a result.

Steps to reproduce

I just compiled this code on Windows 10, with TMD-GCC 5.1 :

TEST_CASE("whatever") {
    Catch::getEstimatedClockResolution();
}

and I got the behaviour I explained before.

So I looked in the source code and I extracted the critical section, adding some prints to see what's going on :

TEST_CASE("whatever") {
	for (int i = 0; i < 1000; i++) {
		uint64_t ticks;
		uint64_t baseTicks = Catch::getCurrentNanosecondsSinceEpoch();
		std::cout << baseTicks << std::endl;
		do {
			ticks = Catch::getCurrentNanosecondsSinceEpoch();
		} while (ticks == baseTicks);
		std::cout << ticks << std::endl;
	}
}

I got the following output :

1522549011516507900
1522549011517508200
1522549011517508200
1522549011518510100
1522549011518510100
1522549011519510000
1522549011519510000
...

My resolution seems awful, and thus the estimation takes way too much time. Works well on Visual studio though, I have this output :

3470278496901559
3470278497438427
3470278497653964
3470278497868317
3470278498082275
3470278498319523
3470278498539007
3470278498762834
...

Suggested solution

Put a time limit to Catch::estimateClockResolution ?

Extra information

  • Catch version: v2.2.1
  • Operating System: Windows 10
  • Compiler+version: TMD-GCC 5.1
@horenmar

This comment has been minimized.

Member

horenmar commented Apr 1, 2018

libstdc++ on Windows strikes again!

I'll see about adding an early bailout to the loop, so we don't spin forever when met with low precision clocks.

@horenmar

This comment has been minimized.

Member

horenmar commented Apr 1, 2018

I added an experimental bailout code that aborts the calibration after 3 seconds.

Note that benchmarks under such timer should be taken with huge grain of salt and will not be overly representative of reality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment