Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: The elements of enlightenment




On 2022-12-05 13:49, Roman Perepelitsa wrote:
That's why I tried to quantify it in related terms: on my machine
executing that thing 100 times takes over a second.

     % time ( repeat 100 var=$(printf hello) )
     user=0.00s system=1.06s cpu=90% total=1.178

     for k v in ${(kv)options}; do
	# 100X slower!!!
	#list+=$( printf '%-20s %s%s\e[0m\n' $k ${color[$v]} $v )
	printf -v line '%-20s %s%s\e[0m' $k ${color[$v]} $v
	list+="$line"
     done

Even buried back in the entire function, where the difference is somewhat swamped by the time the other code takes to run,  it's still 100X faster doing it your way.  Sheesh, it's quite astonishing. I probably wouldn't understand the answer anyway but I hafta wonder why this forking is so necessary.  But for now 'print -v var' is my new friend.






Messages sorted by: Reverse Date, Date, Thread, Author