The current accepted answer for this question (by ghostdog74) provides a method that executes extremely slowly for even a moderately high number of characters. The top-voted answer (by CaffeineConnoisseur) is better, but is still quite slow.
Here is what, in my tests, has executed fastest of all (even faster than the python version):
perl -E "print '*' x 1000"
In second place was the python command:
python -c "print('*' * 1000)"
If neither perl nor python are available, then this is third-best:
head -c 1000 /dev/zero | tr '\0' '*'
And in fourth place is the one using the bash printf
built-in along with tr
:
printf '%*s' 1000 | tr ' ' '*'
And here's one (from CaffeineConnoisseur's answer) that's in fifth place in speed for large numbers of repeated characters, but might be faster for small numbers (due to using only a bash built-in, and not spawning an external process):
printf '%.s*' {1..1000}