How quickly can the computer check me?
September 8, 2006 6:29 PM   Subscribe

How fast can a computer check to see if a key has bee pressed?

Curious: Say I got a mac mini 1.4ghz and I type at 30 words a minute. How often can the computer check to see if a key has been pressed in between typing, any two letters as I typed this sentence.

Would it matter if it was a simple application or something coded into the OS (i.e. would one be faster than the other?) Would this constant checking slow down the computer? Would getting a faster computer enable the it to check faster and/or better?
posted by Brandon Blatcher to computers & internet (26 answers total) 3 users marked this as a favorite
 
A chip in the keyboard scans the keys over and over again (probably hundreds of times per second). When it notices something's changed, it sends a signal to the computer, which triggers an interrupt in the processor which processes the change, possibly sending an event to an application. There's no need for the actual computer to do any scanning.

What's this for?
posted by cillit bang at 6:35 PM on September 8, 2006


What's the difference between the chip in the keyboard and the main computer?


It's for a possible story...I'm wondering what the passage of time would be like for a sentient computer: would it be thinking superfast and would signals from a keyboard seem to take forever from it's point of view?
posted by Brandon Blatcher at 6:40 PM on September 8, 2006


I'd describe an interrupt as like being poked - jarred out of your thoughts and having to put them on hold until you've filed the new keypress. It could be kind of irritating :)
posted by -harlequin- at 6:55 PM on September 8, 2006


Let's say someone is typing at a ridiculous speed - say, 300 wpm. If a word is on average 6 characters, that's about 1800 cpm or 30 cps. Now consider a modern computer with a clock cycle of about 1 gigahertz (1 billion cycles per second). This means that the computer goes through upwards of 30 million cycles between keystrokes.
posted by neckro23 at 6:57 PM on September 8, 2006


Orders of magnitude faster than you can type.

The keyboard on a PC returns key down and key up events to the OS which can be measured in microseconds.
posted by scheptech at 7:00 PM on September 8, 2006


This means that the computer goes through upwards of 30 million cycles between keystrokes.

Would say that a single "cycle" would be the equivalent of human being checking their watch?
posted by Brandon Blatcher at 7:04 PM on September 8, 2006


Actually, it takes a while for the microprocessor in the keyboard because it has to debounce. Keys are not clean switches, though the keyboard designers do their best. When pressed, the key will make and break contact several times. The chip in the keyboard has to detect the press on several successive scans to make sure that it's down and that it's staying down before it reports it to the CPU. (Well, not necessarily, but that's how it's done.) It usually takes a millisecond or two for the key to stop bouncing.

There's also latency inside the CPU in processing the interrupt before the key code becomes available for whatever application currently has focus. However, the main limit is probably how well the app itself is written -- and in some cases that is truly awful, especially when programs are written for the hideous execution models used by classic Windows and MacOS classic.
posted by Steven C. Den Beste at 7:09 PM on September 8, 2006


A single cycle would be a very very simple operation - the smallest discreet unit of thought, kinda like the atoms that make up an apple. Checking your watch is an apple - a very complicated action in comparison. Maybe if thought were expressed as words, eg "I should find out what the time is", each word would be several cycles.
"To find out the time, I must check my watch"
"To check my watch, I must:
- raise my arm
- rotate my wrist
- etc etc"

But still, with 30 million cycles to throw around, that's still a lot of apples (or checking your watch) between keypress inputs.
posted by -harlequin- at 7:11 PM on September 8, 2006


In short -- fast. This applies to the IBM AT keyboard system. Others will vary.

The keyboard clock signal stays high until a keypress is detected. It then goes low for 36μS, then it strobes nine times, 20μS high, 12.5μS low. During the eight clock pulses, the data line is set high or low for the first seven pulses, this is the keycode (some keystrokes require multiple keycodes.) The 8th is even parity, then the clock signal goes back high until the next signal needs to be sent.

Effectively, you get about 31Kbps through the controller, so there's your best resolution -- 1/31000 sec. This drops slightly if there's lots of host-keyboard interaction (toggling LEDs, ect.)

Getting 1/15000 second resolution is trivial.

SCDB -- the keyboard processor traditonally ran at 4.77Mhz, since about 1985, they're running at 6Mhz. There's plenty of time to clean up the keypress signals, the fundamental limit is the keyboard bus.
posted by eriko at 7:27 PM on September 8, 2006


If you agree with necro23's numbers of 30 million cycles between keystrokes, it may seem like forever to you, but a computer is really good at multitasking. It can and will be doing tons of other stuff with those 30 million cycles. The same could be assumed of a sentient computer. And because a sentient computer would not hesitate to put those 30 million cycles to good use I doubt it would even consider the relative concept of "forever' between strokes any more than someone who plays chess by mail with a stranger would think the game is taking forever. The game still progresses, one move at a time, just more extraneous activity occurs in between.

As an aside, input wether it be written or spoken or the clicking of tongues to morse code is usually measured in words per minute. The record holding typist has maintained 150 wpm for 50 minutes, 170 wpm for shorter periods of time, and has been clocked at a peak speed of 212 wpm.

Now pretend you're on the other end of an instant message against this record holding typist where each word appears ass soon as it is typed. According to the same wikipedia link educated adults read at 200-350 wpm, so it's reasonable to assume that a 1 for 1 level out output and comprehension is possible at 200 words per minute with just humans on each end. That should give you some perspective to work with compared to 30 million cycles between characters.
posted by furtive at 7:31 PM on September 8, 2006


Consider that it takes 150-200 milliseconds (thousandths of a second) for a human to react in a simple reaction time experiment -- that is, where you have to press a button as soon as you see a light or hear a sound. Some of that time is used for perception, a little bit is involved in triggering the motor response, and a bit is taken up by the physical movement (there are people who have made careers out of dissecting what happens in this short period of time, and how the different phases can overlap, etc.)

Choice reaction times (where you have to press a different button depending on which letter or sound a computer makes, for example) are typically in the range of 350-500 ms, with the number of possible stimuli, the complexity and similarity of the stimuli, and the nature of the mapping between the stimuli and response types having a big influence on matters.

Converting between the human and computer scales is an exercise left up to the reader.
posted by i love cheese at 7:34 PM on September 8, 2006


For a sentient computer, think of a keystroke as a photon entering your eye. Its a very small discrete package that you [usually] need a lot of to make any sense out of, really, but you're not concentrating on how fast they're coming in, or even that they're coming in. Your mind is doing stuff the entire time, & only focuses on what its seeing when it needs to.

That's the way I'd spin it, at least.
posted by devilsbrigade at 7:36 PM on September 8, 2006


If you agree with necro23's numbers of 30 million cycles between keystrokes, it may seem like forever to you, but a computer is really good at multitasking. It can and will be doing tons of other stuff with those 30 million cycles.


Yeah, i got THAT, but in terms of waiting for the input from the keys, it might seem like forever, while it was still doing a bunchof ohter things, yes? Sort of like a person cleaning up the house while waiting for that important phonecall: sure you got other stuff going on, but damn phone still isn't ringing, when you're hoping/expecting it to.
posted by Brandon Blatcher at 7:54 PM on September 8, 2006


There's a difference between sentience and impatience.
posted by furtive at 8:14 PM on September 8, 2006


Although, your Mac Mini's keyboard connection is USB, and USB "interrupts" (which are not actually interrupts) can only occur once per USB frame, which means once per millisecond. The keyboard sends back anything it needs to in response to an automatic poll from the USB controller on the host. If anything comes back, the USB controller interrupts (a real interrupt this time) the CPU in order to give it the information.

I'm not sure what a good analogy for this would be. An intra-office mail cart that comes by exactly once an hour? The traffic-and-weather report on the radio?
posted by hattifattener at 8:19 PM on September 8, 2006


Sentience implemented on a computer is likely to require parallel processing on a massive scale. A standard CPU has very limited parallel processing ability, so the required parallelism would most likely be simulated using time-sharing between multiple threads of program execution. The sentience would be about as unlikely to have meaningful access to the internals of these as you have to the detailed activity of your own neurons, and would almost certainly have no innate sense of its own CPU speed; it would judge the time between keypresses as fast or slow compared to the times between other inputs from its environment, rather than comparing them to its own CPU speeds.

So the passage of time for a sentient computer would be much like it is for us: events would be processed at whatever rate is appropriate to allow the sentience to operate successfully within its environment, and events occurring at far faster or slower rates than that would be either ignored, transformed from the time domain to the frequency domain, or chunked.

For example: if you're near a speaker emitting sound at 2kHz, then there are 2000 pressure waves arriving at your eardrum each second. But your brain doesn't separate events that happen much faster than about 10 per second; so instead of hearing each pressure wave as a click, you hear a pure tone.

It seems to me that the most likely effect of increasing the CPU speed of a sentient computer system would be to make it able (and therefore likely) to pay attention to more things at once, rather than causing it any discomfort due to the sloth of its inputs.

Of course, if you're writing a fantasy based on the notion of sentience as something that can be acquired by magic, as opposed to something that actually needs a system dedicated to its implementation, you can make your sentience have any kind of subjective experience you like.
posted by flabdablet at 8:36 PM on September 8, 2006


Actually, it's probable that our brains operate at a higher clock speed than most computers, due to the massively parallel processing that goes on in our minds.
posted by chrisamiller at 8:38 PM on September 8, 2006


Judging from the way Brandon Blatcher has framed his question and subsequent comments, I'm guessing that this sentient computer is waiting for important information from the user.

Consider for instance a family waiting for a call from a kidnapper. Yes, they can and probably are doing a lot of things while waiting for that call, but the focus of the vast majority of all that processing power will be on waiting desperately for the next input.
posted by willnot at 9:18 PM on September 8, 2006


I thought Cory Doctorow's latest short story I, Rowboat did an excellent job of describing how a sentient computer might percieve the passage of time. Do you know how things seem to move slower as your mind races in an emergency? Or conversely, how hours fly by while you day dream? Imagine being able to do that at whim.
posted by Popular Ethics at 9:56 PM on September 8, 2006


Judging from the way Brandon Blatcher has framed his question and subsequent comments, I'm guessing that this sentient computer is waiting for important information from the user.

Yes. Though I'm realizing that in this sense, computer speed won't matter, because it's placed a priotory on the input and it's waiting for THAT as opposed to the various other things it's doing.

But would that "subjective" view of time be different or just on a different scale? Will it view the time between keys depressing as we we view minutes? or weeks? or years? Would it be like some teenager, waiting desparately by the phone? or like some anicent druid, waiting for yearly ritual to decode the message from the gods? or would it be good and insane, "hearing" these random "voices"?
posted by Brandon Blatcher at 7:51 AM on September 9, 2006


A sentient computer "sensing" key presses would be roughly the same as you, as a human, "sensing" individual pulses of vibrating air that your brain interprets as sound.
posted by odinsdream at 9:38 AM on September 9, 2006


Or, what flabdablet said.

Computers don't "wait" for input, though. The various processors in the computer cooperate through interrupts. If the keyboard needs attention because keys have been pressed, it asks for attention from the processor. The processor chooses to listen or not, but these choices happen billions of times a second. So, it could decline to listen ten thousand times, then decide to listen on the next cycle. You, however, would have just finished releasing the spacebar by the time these ten thousand requests had been declined.
posted by odinsdream at 9:42 AM on September 9, 2006


If you really, really, really need it to seem like it's impatiently waiting forever, just write it that way already. At that point what real keyboards on real computers do is completely irrelevant anyhow.
posted by mendel at 1:10 PM on September 9, 2006


just write it that way already

yah, but i was CURIOUS and what more info.
posted by Brandon Blatcher at 4:05 PM on September 9, 2006


Yes, but everyone has come in to tell you how it does not work how you expected it to work, and you keep saying "but couldn't it be like this INSTEAD", and the answer to that is "It is not like that, but you are free to do so in your story".
posted by mendel at 4:20 PM on September 9, 2006


Thank you, everyone, for taking the time to chime in with explanations. It's very much appreciated.
posted by Brandon Blatcher at 7:00 PM on September 9, 2006


« Older I've created a button in Excel...   |  I am having a really strange c... Newer »
This thread is closed to new comments.