help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Too fine design granularity leads to numerous macro/function/command


From: Hongyi Zhao
Subject: Re: Too fine design granularity leads to numerous macro/function/command existed in Emacs.
Date: Sat, 14 Aug 2021 09:02:06 +0800

On Sat, Aug 14, 2021 at 8:43 AM Emanuel Berg via Users list for the
GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
> Hongyi Zhao wrote:
>
> > It's not difficult for me or maybe some others, just too
> > lazy to think for a while.
>
> A lot of people like to think their lack of [whatever] is
> because of laziness, however as for thinking of new reasons to
> be lazy, the sure are hard at work. (I don't think that
> applies to you but be careful with that word.)
>
> > After all, we have so many
> > convenient uinx tools and the excellent (but with
> > performance penalty) pipe method at hand. Anyway, I've
> > presented a comparison between pure AWK and UNIX toolchains
> > as follows:
> >
> > $ time awk 'length > max_length { max_length = length; longest_line =
> > $0 } END { print longest_line }' american-english-exhaustive
> > correspond with someone about someone or something correspond with
> > someone about someone or something
>
> OK, great, so you got the one-liner to work, what did
> you change?

Another reason I prefer UNIX toolchains is that they have been tried
and tested by many people for many years, and using your own temporary
code may expose you to greater risk of errors. Though I have to bear
some performance losses, but compared with today's fast computers,
this is insignificant in many test scenarios.

> > real    0m0.255s
> > user    0m0.255s
> > sys    0m0.003s
> >
> > $ time awk '{ print length($0) " " $0; }' american-english-exhaustive
> > | sort -n | tail -1| cut -d ' ' -f2-
> > correspond with someone about someone or something correspond with
> > someone about someone or something
> >
> > real    0m1.794s
> > user    0m1.853s
> > sys    0m0.053s
> >
> > Obviously, the former is about 6 times faster than the latter.
>
> Cool, try my command as well:
>
>   $ awk '{ print length($0) " " $0; }' $file | sort -n | tail -1
>
> The reason the piped commands are slower are because of the
> context-switches so instead of time(1) try this command for
> all three:
>
>   $ perf stat sh -c 'COMMAND'

See below, but I'm not familiar with this tool, so don't understand
his output very well:

$ sudo perf stat sh -c "awk '{ print length($0) " " $0; }'
american-english-exhaustive  | sort -n | tail -1| cut -d ' ' -f2-"
bash; }' american-english-exhaustive  | sort -n | tail -1| cut -d ' '
-f2-: 1: Syntax error: Unterminated quoted string

 Performance counter stats for 'sh -c awk '{ print length(bash)
bash; }' american-english-exhaustive  | sort -n | tail -1| cut -d ' '
-f2-':

              0.85 msec task-clock                #    0.661 CPUs
utilized
                 0      context-switches          #    0.000 K/sec
                 0      cpu-migrations            #    0.000 K/sec
                62      page-faults               #    0.073 M/sec
         1,012,717      cycles                    #    1.193 GHz
           903,160      instructions              #    0.89  insn per
cycle
           182,165      branches                  #  214.508 M/sec
             8,022      branch-misses             #    4.40% of all
branches

       0.001285545 seconds time elapsed

       0.001390000 seconds user
       0.000000000 seconds sys

Hongyi



reply via email to

[Prev in Thread] Current Thread [Next in Thread]