Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14485

Re: Unexpected delay in using arguments.

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: Unexpected delay in using arguments.
Date 2018-08-14 11:25 -0400
Message-ID <mailman.5096.1534260312.1292.bug-bash@gnu.org> (permalink)
References <CAFra36j=UuqHv2Spp26ebAW0dRW+KsgNS21hZJrwuku9QUayWw@mail.gmail.com>

Show all headers | View raw


On 8/12/18 3:16 AM, Bize Ma wrote:
> Try this script:
> 
>     #!/bin/bash
>     TIMEFORMAT='%R'
> 
>     n=1000
>     m=20000
> 
>     f1   () { :; }
> 
>     f2   () { i=0;  time while [ "$((i+=1))" -lt "$n" ]; do     :    ; done
>           i=0;  time while [ "$((i+=1))" -lt "$n" ]; do     f1    ; done
>         }
> 
>     test1() { set -- $(seq $m)
>           f2  ""
>           f2 "$@"
>         }
>     test1
> 
> To get:
> 
>       0.019
>       0.028
>       0.019
>     19.204
> 
> Which is a thousand times slower.

If you build a profiling version of bash, you'll find that about 75% of
that time is spent copying the list of arguments around, since you have
to save and restore it each time you call f1. Looking at making that more
efficient has been a low-level task for a while now.

> Bash 5 is even worse, try:

Bash-5.0-alpha is not a released version, so it uses the debugging malloc.
If you profile that, you'll find that about 99% of the time is spent
marking allocations as active and free in the table the bash malloc uses
to keep track of active memory.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Back to gnu.bash.bug | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Unexpected delay in using arguments. Chet Ramey <chet.ramey@case.edu> - 2018-08-14 11:25 -0400
  Re: Unexpected delay in using arguments. Stephane Chazelas <stephane.chazelas@gmail.com> - 2018-08-14 23:21 +0100

csiph-web