Well, it's not a few seconds thought. It can happen when you try (defend) a case that you realize, at some point during the prosecution's case-in-chief, that he has made a fatal error or omission. And the judge may realize it, too. And so as soon as the prosecutor rests you make your successful motion to dismiss. The judge grants it summarily because he, too, has noticed the error, for some time, and when the prosecution rests it is, at that moment, TOO LATE to correct the defect.
So a judge can grant or decide immediately -- it doesn't mean he hasn't been thinking about it all the way through the case.