Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: The elements of enlightenment
On Mon, Dec 5, 2022 at 8:36 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> But, since setopt is a builtin anyway, why not just use it as is?
Parsing things from text is usually more complex than dealing with the
things that are already in a decent data structure. Your specific task
may be an exception if you really want to produce the same output as
`setopt` but with "off" in red. In this case it may be even desirable
to manipulate the output of `setopt` rather than reconstructing it
manually.
> printf is heavy, no? setopt might be lighter?
Neither printf nor setopt are heavy. Forks are extremely inefficient
though. The cost of a fork is almost astronomical compared to simple
operations. The following two lines achieve the same thing:
var=$(printf hello)
printf -v var hello
On my machine the first line is 1500 times slower than the second. You
need to execute this line only 100 times in order to have the total
run time of a script in excess of 1 second. Imagine if every line of a
script was this slow.
Roman.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author