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

1897 questions
131
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.
dato datuashvili
  • 16,915
  • 53
  • 184
  • 303
109
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,191
  • 2
  • 8
  • 4
102
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
  • 148,751
  • 62
  • 182
  • 223
74
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
  • 10,331
  • 11
  • 39
  • 56
71
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
  • 5,766
  • 36
  • 58
68
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
  • 73,106
  • 23
  • 158
  • 198
63
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,378
  • 3
  • 28
  • 45
57
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
  • 3,851
  • 2
  • 26
  • 30
56
votes
11 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,676
  • 8
  • 39
  • 56
56
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,455
  • 6
  • 31
  • 38
56
votes
6 answers

How to sync time on host wake-up within VirtualBox?

I am running an Ubuntu 12.04-based box inside of Vagrant using VirtualBox. So far, everything is fine - except for one thing: Let's assume that the VM is running. Then, the host goes to standby-mode. After waking it up again, the VM is still…
Golo Roden
  • 112,924
  • 78
  • 260
  • 376
56
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,029
  • 3
  • 12
  • 16
51
votes
9 answers

Update TextView Every Second

I've looked around and nothing seems to be working from what I've tried so far... @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.deskclock); TextView tvTime…
Timmo
  • 2,058
  • 4
  • 29
  • 51
47
votes
6 answers

Getting iOS system uptime, that doesn't pause when asleep

I'm looking for a way to get an absolute, always-incrementing system uptime on iOS. It should return the time since the device was last rebooted, and not be affected by changes to the system date. All the methods I can find either pause when the…
Russell Quinn
  • 1,290
  • 1
  • 11
  • 14
44
votes
5 answers

Display a time clock in the R command line

I wonder if there is a way to display the current time in the R command line, like in MS DOS, we can use Prompt $T $P$G to include the time clock in every prompt line. Something like options(prompt=paste(format(Sys.time(), "%H:%M:%S"),"> ")) will…
Shu
  • 571
  • 4
  • 5
1
2 3
99 100