Questions tagged [clock]

Hardware and system clocks used by drivers, OS and hardware languages.

Clocks are key to controlling synchronous logic and are used by drivers, and OS software. As well, hardware languages, such as and can make extensive use of clocks. CPU or system clocks are familiar to most developers, but a typical computer can contain many different clocks to control different hardware functions such as video, audio, RAM, buses, etc. Familiar current time functions are often derived from a hardware clock which produces interrupts allowing an OS to keep a running time count by recording the interrupt; sometimes called ticks or jiffies.

Related tags

  • - obtaining, formatting times and other uses.
  • - program issues dealing with dates.
  • - measuring execution time with a clock.

See also: PLL, Clock divider

2060 questions
270
votes
8 answers

Difference between CLOCK_REALTIME and CLOCK_MONOTONIC?

Could you explain the difference between CLOCK_REALTIME and CLOCK_MONOTONIC clocks returned by clock_gettime() on Linux? Which is a better choice if I need to compute elapsed time between timestamps produced by an external source and the current…
NPE
  • 486,780
  • 108
  • 951
  • 1,012
140
votes
7 answers

How to use clock() in C++

How do I call clock() in C++? For example, I want to test how much time a linear search takes to find a given element in an array.
user466534
139
votes
16 answers

WSL2 Clock is out of sync with Windows

WSL2 clock goes out of sync after resuming from sleep/hibernate. A workaround was shared on GitHub sudo hwclock -s to resync clock in WSL, but you have to do this every time you resume from sleep/hibernate.
piouson
  • 3,328
  • 3
  • 29
  • 29
117
votes
7 answers

Will a docker container auto sync time with its host machine?

Do I need a NTP server inside a docker container to periodically sync the time or will the container re-sync time with its host machine? The docker container time zone is correctly set.
vantt
  • 1,271
  • 2
  • 9
  • 4
103
votes
16 answers

C++ obtaining milliseconds time on Linux -- clock() doesn't seem to work properly

On Windows, clock() returns the time in milliseconds, but on this Linux box I'm working on, it rounds it to the nearest 1000 so the precision is only to the "second" level and not to the milliseconds level. I found a solution with Qt using the QTime…
hasen
  • 161,647
  • 65
  • 194
  • 231
81
votes
2 answers

What happened to clockless computer chips?

Several years ago, the 'next big thing' was clockless computers. The idea behind it was that without a clock, the processors would run significantly faster. That was then, this is now and I can't find any info on how it's been coming along or if…
GeoffreyF67
  • 11,061
  • 11
  • 46
  • 56
74
votes
7 answers

Is it legal for a C++ optimizer to reorder calls to clock()?

The C++ Programming Language 4th edition, page 225 reads: A compiler may reorder code to improve performance as long as the result is identical to that of the simple order of execution. Some compilers, e.g. Visual C++ in release mode, will reorder…
Paul Jurczak
  • 7,008
  • 3
  • 47
  • 72
72
votes
13 answers

clock_gettime alternative in Mac OS X

When compiling a program I wrote on Mac OS X after installing the necessary libraries through MacPorts, I get this error: In function 'nanotime': error: 'CLOCK_REALTIME' undeclared (first use in this function) error: (Each undeclared identifier is…
Delan Azabani
  • 79,602
  • 28
  • 170
  • 210
69
votes
8 answers

Time in milliseconds in C

Using the following code: #include #include int main() { clock_t start, stop; int i; start = clock(); for(i=0; i<2000;i++) { printf("%d", (i*1)+(1^4)); } printf("\n\n"); stop = clock(); …
user980411
  • 1,179
  • 3
  • 12
  • 18
68
votes
8 answers

Emulator's clock doesn't match the host system clock

Why doesn't the Android emulator's clock match the host system clock? It's not a time zone difference--it's always off by several minutes. Is there a way to synchronize them besides manually setting the emulator's time?
Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
67
votes
5 answers

Timing algorithm: clock() vs time() in C++

For timing an algorithm (approximately in ms), which of these two approaches is better: clock_t start = clock(); algorithm(); clock_t end = clock(); double time = (double) (end-start) / CLOCKS_PER_SEC * 1000.0; Or, time_t start =…
blaze
  • 2,588
  • 3
  • 32
  • 47
62
votes
12 answers

How to create a JQuery Clock / Timer

I have a simple quiz application and I want display a nice timer / clock at the top of the page which shows the user how long they've been going for. (If I could somehow show them a timer for Total Quiz Time and also a second one for This Question…
Ganesh Shankar
  • 4,826
  • 8
  • 43
  • 56
59
votes
5 answers

How do I get monotonic time durations in python?

I want to log how long something takes in real walltime. Currently I'm doing this: startTime = time.time() someSQLOrSomething() print "That took %.3f seconds" % (time.time() - startTime) But that will fail (produce incorrect results) if the time is…
Thomas
  • 4,208
  • 2
  • 29
  • 31
58
votes
2 answers

What is a clock cycle and clock speed?

I have been reading a book about the Computer's Processor. And I came across some of the terms like clock Ticks, clock Cycle and clock Speed that I am finding very difficult to understand. I will be very thankful if someone can clarify this in a…
user7876385
57
votes
6 answers

How do I calculate the elapsed time of an event in Java?

What's a simple/easy way to access the system clock using Java, so that I can calculate the elapsed time of an event?
kafuchau
  • 5,573
  • 7
  • 33
  • 38
1
2 3
99 100