Mythbusters recently did a horrible "21 Foot Rule" test (above). Many things were wrong with it (Adam saw the attack coming, gun was unloaded with safety on, etc) but we get the general idea. A knife-wielding maniac can close the distance pretty fast. More disturbing though, are some of the comments I've seen claiming that you shouldn't try for your gun in this situation, but rather should do karate on the knife-wielding maniac.
The main karate argument is that since you can't fire before you get stabbed, you should just fight the armed bad guy with your Chuck Norris skills.