Re: Performance bug of {1..1000000}?
On 3/7/20 10:39 AM, Peng Yu wrote: See the following run time comparison. {1..100} is slower than $(seq 100). Since seq involves an external program, I'd expect the latter to be slower. But the comparison shows the opposite. I guess seq did some optimization? seq does not have to store the entire sequence in memory. As it outputs things to stdout (and the other end of the pipeline consumes that output), seq can forget what it has previously done. Bash, on the other hand, computes the entire expansion in memory prior to proceeding to use that expansion. It is the cost of memory allocation and increased memory usage that slows bash down. Can the performance of {1..100} be improved so that it is faster than $(seq 100)? Not without someone writing a patch. Are you volunteering? But in general, we don't recommend trying to make bash do expansions like that, when it is already more efficient to use other means of iteration that do not require bash to keep the entire sequence in memory. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Assign Default Value expansion inserts ASCII DEL for empty 'word'
Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -DDEFAULT_PATH_VALUE='/usr/local/sbin:/usr/local/bin:/usr/bin' -DSTANDARD_UTILS_PATH='/usr/bin' -DSYS_BASHRC='/etc/bash/bashrc' -DSYS_BASH_LOGOUT='/etc/bash/bash_logout' -DNON_INTERACTIVE_LOGIN_SHELLS -Wno-parentheses -Wno-format-security uname output: Linux arctic 5.5.6-artix1-1 #1 SMP PREEMPT Tue, 25 Feb 2020 14:57:48 + x86_64 GNU/Linux Machine Type: x86_64-pc-linux-gnu Bash Version: 5.0 Patch Level: 16 Release Status: release Description: Out of nowhere, bash inserts an ascii DEL in the first expansion. That is very unexpected and shouldn't be there. Repeat-By: $ unset foo bar $ echo "${foo:=}/baz:${foo}/bat"|xxd : 7f2f 6261 7a3a 2f62 6174 0a ./baz:/bat. $ echo "${foo:=$bar}/baz:${foo}/bat"|xxd : 7f2f 6261 7a3a 2f62 6174 0a ./baz:/bat.
Re: Assign Default Value expansion inserts ASCII DEL for empty 'word'
Date:Mon, 9 Mar 2020 20:28:30 +0059.55 From:Martin Castillo Message-ID: <5ad25080-7c13-9b9c-cff6-12ffee7af...@uni-bremen.de> | Repeat-By: | $ unset foo bar | $ echo "${foo:=}/baz:${foo}/bat"|xxd | : 7f2f 6261 7a3a 2f62 6174 0a ./baz:/bat. | $ echo "${foo:=$bar}/baz:${foo}/bat"|xxd | : 7f2f 6261 7a3a 2f62 6174 0a ./baz:/bat. Your tests are overly complex, and arguably stretch into unspecified behaviour (not that that should have any bearing on this). The problem occurs to happen when (and only when) a empty "default" value is assigned to a variable which is (within the same quoted string) concatenated with some non-empty text (before or after). So "${foo:=}y" or "x${foo:=}" or "x${foo:=}y" but not for any of "${foo:=}" x"${foo:=}" "${foo:=}"y x${foo:=} (etc). It is irrelevant whether the x & y here are literals, or the results of expansions, provided that there is actual data, that is x= ; echo "${x}${foo:=}" works x=x ; echo ${x}${foo:=}" inserts the DEL as the value of ${foo:=} kre