Created
January 27, 2019 08:55
-
-
Save hakomo/361c05bd076593e54430e3753775b844 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Topcoder Server の時間計測は rdtsc 以外壊れています | |
// 以下のコードで正しく時間計測ができます | |
// サブミットするときに #define LOCAL を消してください | |
#define LOCAL | |
#ifdef LOCAL | |
#include <chrono> | |
inline double getTime() { | |
using namespace std::chrono; | |
return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count() / 1000.0; | |
} | |
#else | |
inline double getTime() { | |
unsigned long long a, d; | |
__asm__ volatile ("rdtsc" : "=a" (a), "=d" (d)); | |
return (d << 32 | a) / 2.8e9; | |
} | |
#endif | |
#include <iostream> | |
using namespace std; | |
int main() { | |
double startTime = getTime(); | |
while (getTime() - startTime < 1.5) { | |
} | |
cout << getTime() - startTime << " seconds" << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment