[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Useless use of shell pipelines [was: Useful use of dd]



On Sat, Jul 03, 2021 at 10:23:39AM +0200, l0f4r0@tuta.io wrote:
> 2 juil. 2021, 23:30 de dpchrist@holgerdanske.com:
> > $ cat useless-use-of-grep
> > This is the first line: bla bla bla.
> > This is line xxxx: bla bla bla.
> > This is the last line: bla bla bla.

> Here is a better `sed` if you want a all-in-one: 
> sed -n /xxxx/{s/bla/foo/p} useless-use-of-grep

Also:
awk '/xxxx/{sub("bla", "foo"); print}' useless-use-of-grep

> > $ time for n in {1..10000}; do perl -ne 's/bla/foo/ && print if /xxxx/' useless-use-of-grep > /dev/null; done
> >
> > real	0m23.624s
> > user	0m14.308s
> > sys	0m10.826s

> I'm not in front of my Linux terminal, can someone launch the `time` command for my `sed` above please ? :)

unicorn:~$ time for n in {1..10000}; do perl -ne 's/bla/foo/ && print if /xxxx/' useless-use-of-grep; done >/dev/null
real 16.034  user 11.555  sys 4.847

unicorn:~$ time for n in {1..10000}; do sed -n '/xxxx/{s/bla/foo/p}' useless-use-of-grep; done >/dev/null
real 11.489  user 8.670  sys 3.251

unicorn:~$ time for n in {1..10000}; do awk '/xxxx/{sub("bla", "foo"); print}' useless-use-of-grep; done >/dev/null
real 15.690  user 11.575  sys 4.532

Sed wins this particular race, not surprisingly.


Reply to: