Such a simple question. The answer should be like that. But it is not. The simple questions that young children ask are usually the most complex.
What time did you mean?
Coordinated Universal Time (UTC)?
International Atomic Time (TAI)?
Einstein's interpretation of time?
Did you know that even your brain has 2 clocks? See: Circadian Rhythms.
Why am I complicating things? You probably meant my late grandfather's old wall clock.
Not. The question was about: System time.
This introduction is just a confirmation that there are many words in our vocabulary whose meaning we usually do not fully understand. For example, different senses such as smells, tastes, sensations of different colors, music, sounds, "fast", "slow", sweet, hot, sour, bitter, warm, cold, sensations of touch such as hard and soft,.. exist only as a kind of "illusions" inside our brain. Outside our brain, it is about something completely different. Usually much more complex. This kind of "naive reality" is an evolutionary adaptation to the environment in which we live. This enables the successful survival of all animal species on planet Earth. With this kind of evolved sense and perception, we would probably be ineffective outside our home planet.
Let's examine our situation.
Suppose we want to measure the reaction time from the moment an image file is displayed on the screen (or for an audio file when it starts playing).
Let it be:
t1 = time when the trigger file started playing.
After that, we want to measure the time when the participant pressed the key on the keyboard.
Let it be:
t2 = the time when the participant pressed the keyboard key.
The reaction time is:
rt = t2 - t1.
So simple. But it is not.
The evidence for this is numerous doctoral dissertations and scientific-professional papers dealing with checking the accuracy of time measurement from different operating systems (OS). You should always trust what is measured, not what is written in the documentation (if you are able to measure).
At least 99.99% of today's computers are mainly for entertainment and spending free time. Possibly as an advanced typewriter. Such computers are designed to perform multiple different processes simultaneously. The OS of such computers are programmed to save energy and load the CPU as little as possible. Otherwise, for example, you could use your laptop computer to fry eggs, that is, your laptop would not be so attractive and thin, and no one would want to buy it. In contrast, the computer that registers changes in pressure and temperature sensors and operates the control rods in a nuclear reactor works in a completely different way. Well, 1 second of delay can mean what we experienced on April 26, 1986.
The simplified diagram of how a computer application works is:
User <==> Application <==> Operating system (OS) <==> Computer hardware.
So, a computer application almost always depends on the OS. Even this application that runs using the Java virtual machine (JVM). Java is platform independent, but this does not mean that Java does not receive any information from the OS on your computer. Of course, each application (as well as the OS) depends on the hardware used. We can freely say about the OS: "He is the boss". But we know who's the big boss in the house, when the door closes (CPU).
To oversimplify, every desktop application reads "time" (more precisely: TSC) from the Central processing unit (CPU) at the end of the story. We can compare the CPU with the Cerebral cortex.
The system clock is typically implemented as a programmable interval timer that periodically interrupts the CPU, which then starts executing a timer interrupt service routine. This routine typically adds one tick to the system clock (a simple counter) and handles other periodic housekeeping tasks before returning to the task the CPU was executing before the interruption. If you want to dive deeper, take a look here.
Machine code is computer code consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). Machine code is "built into" the CPU by its manufacturer. Machine code is the lowest level of communication with computer hardware.
The process of reading timestamps directly from the CPU is described here. The time stamp read by the CPU is extremely precise, by a few orders of magnitude more than what is needed for an application like this. But the main problem lies in the fact that there is a time lag between the moment when our application requested to read the timestamp and the moment when the CPU executed this instruction code. There is also a time delay associated with the Bytecode used by the JVM, but nowadays, this delay is also negligible, at least as far as a PRG application is concerned. There is also the time required for the CPU to execute the requested instruction code, but this is completely negligible.
Another type of problem, which complicates the process of accurate measurement of reaction time: rt=t2-t1, is related to used computer hardware. There is always a hardware response time. For better quality hardware, this time is shorter. Time differences can be very significant. For example, there is Input lag, Display lag, Pixel response time, and general hardware Response time. The CPU usually does not have all this information. This is strongly related to the quality (most often also the price) of the used computer hardware. Beggars can’t be choosers. When I was younger, I did similar experiments like this one and this one.
Like Aleksey Shipilëv said: In some cases, there is no good solution to the problem at hand. Some things are not directly measurable. Some things are measurable with unpractical overheads. Internalize that fact, weep a little, and move on to building the indirect experiments. This is not the Wonderland, Alice. Understanding how the Universe works often needs side routes to explore. In all seriousness, we should be happy our $1000 hardware can measure 30 nanosecond intervals pretty reliably. This is roughly the time needed for the Internet packets originating from my home router to leave my apartment. What else do you want, you spoiled brats?
All this has been stated so far, it sounds quite pessimistic. Does this mean that we should not perform research on non-real-time operating systems that have lower quality hardware? No. With a good research model, you can discover new facts despite the limitations of the measuring equipment at your disposal. If necessary, you can subsequently verify or deny the obtained research results on a real time OS and better computer hardware. PRG application is primarily intended for running research models on non-real-time operating systems and computer hardware of lower or medium quality. Of course, the use of high-quality computer hardware is always welcome.
Always Look on the Bright Side of Life. Do you really think that the measuring equipment used by Franciscus Cornelius Donders, Wilhelm Maximilian Wundt, Ernst Heinrich Weber and Gustav Theodor Fechner in the 19th century was perfect? Probably not, but nevertheless, they made fundamental discoveries. For example, at this link you can study the fundamental scientific work: Donders, F. C. (1868). Over de snelheid van psychische processen. Take a look at the measuring equipment that Donders had at his disposal at the time, and despite this, his results remain irrefutable even after over 150 years.
Nowadays, Psychophysics and Mental chronometry researches are not that popular as some other fields of research. But it is almost the only area left, in which psychologists remain dominant.