String.prototype works slowly in loop