To put it more clearly, the browser will iterate the 5000 elements many times over, doing CPU intensive stuff on each: load them, parse them, render them, resize them, ... One extra pass of 5000 string comparisons won't make noticeable difference.
That doesn't mean the code snippet isn't a WTF : using document.getElementsByTagName("input") instead of document.all (which is IE-script, not JavaScript) would be a good start to improve it