Path: csiph.com!3.us.feeder.erje.net!feeder.erje.net!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Bize Ma Newsgroups: gnu.bash.bug Subject: Re: Unexpected delay in using arguments. Date: Tue, 1 Jan 2019 22:57:37 -0400 Lines: 113 Approved: bug-bash@gnu.org Message-ID: References: <20180814123113518879862@bob.proulx.com> <20180815011219279040096@bob.proulx.com> <9a4dd312-8e3e-4b6a-05d5-699855bbfedf@case.edu> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: usenet.stanford.edu 1546397876 8486 208.118.235.17 (2 Jan 2019 02:57:56 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash To: Chester Ramey Envelope-to: bug-bash@gnu.org 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 :cc; bh=fH8diBSq08zzRjJo6pkqXiSQuqhLwcDpGCSInNTx6UA=; b=AR0nVWmIJo1D5b0tRPkMRQmRimHPttmKKlL3XUoCWlwSP/lYGOFrFvjZRr/+7vsuS2 2Oz06sn6078BcnXLDhB5PHEY1UvO6mf3pGhYrRne5ievdE+ed2WnGJKL4dk0uQXKpTro AK+QKk0lgEpCx0X4fzJYVleJsmm6+MNN5nEhF8brBGWwy1m3F8AZ3jhqaEccX6i8erMJ bJp2ducqN30l2OSKb48mkbhEl4Y4dC+P0ViYsAsE9X1vwsp2y9dIYv2Bc9wuz/piWQlV AQfzHMrYbW4UGSNlV8afNmdOhkgPo6mzW0ahsMAQ1dpDgL6fGmxZeBGBF8ILjH7C60zN pSaA== 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:cc; bh=fH8diBSq08zzRjJo6pkqXiSQuqhLwcDpGCSInNTx6UA=; b=Q0GSvTb0sfCMOCnDTOPLIaUCBae6bPsAckfdYXJCp1b4vAXcDbs/Ma5gxyf/I6qyCI fBD7aPcLPrvR7xq1HwobNsxcy3biNxXfzwd80pjCbRtdbYHdPHnEyw8NUIHDeXEpvnLA A5I/SLXOrvxwhL4LKG51sL/rMsxIdjBgb+3iEiYZYZhwHr3rWFoltJ74EJcbg1BVMKTL SDAgQvyzSK7eiwLN/s1FBG/qdyN+CRYWFJvmCR6Jlep98rc9H5UPitnRLTn7MGCptr2o jDe8mg3kMGke9NOBLWB7vMlOk06JGqnGMEdouOmDOjBxweal0/QfGm66hLggJTXeh0Ir My6g== X-Gm-Message-State: AJcUukfbRNgIoSHKj7apKr1wwiRwSS207oy+55GxfsmwQsZEj//PvwAV YypxD09v35OZCh3iq0ksyed0A5dZHQunSIvp0v4= X-Google-Smtp-Source: AFSGD/XGwDmXSijXsb43MdA7vMqvcPsm178mxo7dy48+nnztKLxvOgJWqLJR2LNJ+zd+EjNvHlcquHPfH19d44OpnVA= X-Received: by 2002:aca:a897:: with SMTP id r145mr29207257oie.253.1546397870166; Tue, 01 Jan 2019 18:57:50 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::232 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:15028 Chet Ramey () wrote: > It's in CWRU/CWRU.chlog in the development distributions > I am sorry but I have been unable to find either the source code or the change log, either at the university site or by looking with google. However, I have made some tests. Yes, the deeper internal delay with arguments have been removed. Running this code (from https://unix.stackexchange.com/q/462084/265604): #!/bin/bash -- TIMEFORMAT='real: %R' f1 () { :; } f2 () { echo ' args = '"$#"; printf '1 function no args yes '; time for ((i=1;i<$n;i++)); do : ; done printf '2 function yes args yes '; time for ((i=1;i<$n;i++)); do f1 ; done set -- printf '3 function yes args no '; time for ((i=1;i<$n;i++)); do f1 ; done echo } main () { set -- $(seq $m) f2 "" f2 "$@" } n=1000; m=20000; main Which had a 20 seconds delay on the second call with arguments (old results): args = 1 1 function no args yes real: 0.012 2 function yes args yes real: 0.033 3 function yes args no real: 0.024 args = 20000 1 function no args yes real: 0.011 2 function yes args yes real: 20.446 3 function yes args no real: 0.021 Has almost removed the *reported *delay (as ksh does): b5b2sh ./script # bash beta 2 args = 1 1 function no args yes real: 0.026 2 function yes args yes real: 0.053 3 function yes args no real: 0.051 args = 20000 1 function no args yes real: 0.022 2 function yes args yes real: 0.052 3 function yes args no real: 0.046 However, the delay is still there, just not reported. Time the whole script to get: time b5b2sh ./script real 0m32.242s The delay has actually increased to 32 seconds, while ksh is able to get: time ksh ./script real 0m0.137s That's 32.242 / 0.137 = 235.343 times longer. It seems that the delay has just moved from the deep internal shuffling of arguments to the phases of creating (and, now also, erasing) the arguments. bash b5b2sh ksh set arguments 0.110 7.404 0.030 args = 1 1 function no args yes 0.014 0.025 0.020 2 function yes args yes 0.027 0.055 0.020 unset arguments 0.000 0.000 0.000 3 function yes args no 0.024 0.053 0.020 call function no args 0.080 5.207 0.070 args = 20000 1 function no args yes 0.011 0.026 0.000 2 function yes args yes 20.430 0.055 0.010 unset arguments 0.003 4.973 0.000 3 function yes args no 0.020 0.048 0.010 call function with args 20.578 23.530 0.040 total 20.788s 41.128s 0.151 It seems odd that now calling the function without arguments takes 5.207 seconds and that the un-setting (set --) the arguments takes 4.973 seconds (setting a pointer to zero should be immediate). While the call to the function is still taking (externally) ~20 seconds. This test seems simpler, easier to run: time b5a0sh -c ' TIMEFORMAT="real: %R"; a=$(seq 20000); f2(){ :; }; echo start>&2; time set -- $a; time f2 "$@"; time set --' Which yields: bash b5b2sh ksh 0.097 8.154 0.020 0.107 39.321 0.020 0.003 5.470 0.000 0.239s 52.975s 0.085s