Is gettimeofday() guaranteed to be of microsecond resolution?
11867927879484732
11867927879692217
it took this long to call printf: 207485
#include <stdio.h>
#include <stdint.h>
inline uint64_t rdtsc() {
uint32_t lo, hi;
__asm__ __volatile__ (
"xorl %%eax, %%eax
"
"cpuid
"
"rdtsc
"
: "=a" (lo), "=d" (hi)
:
: "%ebx", "%ecx");
return (uint64_t)hi << 32 | lo;
}
main()
{
unsigned long long x;
unsigned long long y;
x = rdtsc();
printf("%lld
",x);
y = rdtsc();
printf("%lld
",y);
printf("it took this long to call printf: %lld
",y-x);
}
Tags: unix linux winapi timer visual-c++
Source: By Bernard as answer to the question
This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 4.0
Related code-snippets:
- How can I get the value of in a loop?
- What is error log per Virtual Host?
- What's the API for GTK messagebox?
- How do I get root permission for my file inside vi?
- What does wiggling the mouse do?
- How can I retrieve a windows filename?
- Sharepoint: executing stsadm from a timer job + SHAREPOINTSystem rights + SHAREPOINTSystem rights.
- Windows Equivalent of 'nice'.
- Can I use Xming X Window Server over a VPN?
- How do you create your own moniker (URL Protocol) on Windows systems?
- How can I kill Linux processes older than a certain age?
- How can I fix the Java Time Zone?
- Date arithmetic in Unix shell scripts.
- What's a quicker way to find duplicates conditioned by time?
- How do I encode XML files to XFS,?