From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hongyi Zhao Newsgroups: gmane.emacs.help Subject: Re: Too fine design granularity leads to numerous macro/function/command existed in Emacs. Date: Sat, 14 Aug 2021 09:02:06 +0800 Message-ID: References: <87czqh3b8u.fsf@zoho.eu> <87eeax6w9t.fsf@zoho.eu> <871r6w7vyi.fsf@zoho.eu> <878s146emc.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27117"; mail-complaints-to="usenet@ciao.gmane.io" To: Emanuel Berg , help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 14 03:03:13 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mEi4u-0006rW-UV for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 14 Aug 2021 03:03:12 +0200 Original-Received: from localhost ([::1]:33186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEi4s-0002ba-T3 for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 13 Aug 2021 21:03:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEi46-0002ac-4L for help-gnu-emacs@gnu.org; Fri, 13 Aug 2021 21:02:22 -0400 Original-Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]:45790) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mEi44-0006WW-FH for help-gnu-emacs@gnu.org; Fri, 13 Aug 2021 21:02:21 -0400 Original-Received: by mail-lf1-x130.google.com with SMTP id g13so23106610lfj.12 for ; Fri, 13 Aug 2021 18:02:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Gemc2zePl9s49DOmzov1vnWmZlpkVc7vTyIjeW5gYIk=; b=nrpvN6+9vIW0utRHC98d3Vvr18ST/FJrPRfPZzFkCXXzDIFQcgE/wk4ECUqumaPSli DesLMBCUeVTO9OsA8TfEW8jWq+NcdWsUc6sMU3Fn3xnp8w4rzqXtxx3swy/aKSe8gGNP 5aVwXLWBhHiqXgpbEg+usSrqlj0Sv6/iPLBN2I6YtowWmssJkVCvmanbaH+82jPQBq8f aqQ/K1A+vMKIbfBn8KtVGGvlnPGzxmXpG05kRw9behjCPbgPDYUIdvwXEjkUsdfwIDIe G1qken27ESmELz5v8R9P5QVlf3ba8Ooy19bROMja/un4dY3tCZ15KgvI7ViVMu/xNUyh 1jlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Gemc2zePl9s49DOmzov1vnWmZlpkVc7vTyIjeW5gYIk=; b=HsloqSI0KqJoSFYFEr93OtGmMAf2ecrwLxasOOcgp06NqdXK1Gx+6KGuDdVuQ5OX9p mJ1RURyPGnnV3okenMdq2QKjpI02uRv1Fxpa1Ui5No96+/11bvApoGhzZjb2CrWmTQXy hZ1goH6NUyDQ4V4Q0rC3YSgdedPiIwGRtYjc9MgVozmPldwGI/GXLelWedFWlBs8g/5M 3RXRDVB0ehSXhYO6LWo3XKaVugkkTmifeSmp7zdvpvuUJ320hrc5NsovCWIwFZwLviFx XfGJ134YLjx+O6AE7D+Q95qH9Wmkw5EiLC4xtZk/kQBujWAPjEUjJE/ZpPn4j5xH+X7D jehA== X-Gm-Message-State: AOAM532rxo35EUc0H30UBQN0y8QAe+qsBlF6iPI407I9FT0NNBCtD4hU NQEXRaYsfFKzJ1SdcK9/oAYU/vGd7nO+lLSBkbg= X-Google-Smtp-Source: ABdhPJzfTzVGCnT+5Za2DfYl1/PJwjay9p/cbpEBRCJKoBZmzyTOAYqZlEjMZD2UvideaFmlkEVzRaNVbsGsXBH9NYo= X-Received: by 2002:a05:6512:3fa9:: with SMTP id x41mr3466999lfa.484.1628902938507; Fri, 13 Aug 2021 18:02:18 -0700 (PDT) In-Reply-To: <878s146emc.fsf@zoho.eu> Received-SPF: pass client-ip=2a00:1450:4864:20::130; envelope-from=hongyi.zhao@gmail.com; helo=mail-lf1-x130.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:132523 Archived-At: On Sat, Aug 14, 2021 at 8:43 AM Emanuel Berg via Users list for the GNU Emacs text editor 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