mathiasbynens/String.prototype.repeat — pull request #4 by dtao (2013-12-20 16:10:31+00:00)
Title: suggesting a more optimal repeat implementation

see http://jsperf.com/string-prototype-repeat-polyfill for benchmarks

Basically, say you want to repeat a short string many times. The current implementation creates many intermediate strings, appending the short string to the result over and over. This PR optimizes a little bit by doubling the result as many times as possible (presumably leveraging the browser's optimization of string allocation).

You can see from the jsPerf that—at least on Chrome and Firefox (on my PC)—the performance is about the same for small values of N and significantly better for large values.