Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Alkis Georgopoulos Newsgroups: gnu.bash.bug Subject: Optimize bash string handling? Date: Fri, 26 Jul 2019 12:55:18 +0300 Lines: 29 Approved: bug-bash@gnu.org Message-ID: References: <73adb906-3594-8c38-c820-2bf00b295e22@gmail.com> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1564149162 23668 209.51.188.17 (26 Jul 2019 13:52:42 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=XPzkepx623Sgym/iHFmF1QLq1zKhyTuDZnMrJRtsliE=; b=aKaAJOXoiYyrF2NNN3GGWCUcCFAkalLSHv1xRe5EdTIikvp6aSIn7ibONqmAYiiVO+ KoPglHPKFBOJLuL+tnYWeExSjPgJpoBuJPJG6bHJuyy4c4jRCgecZzhc4el6+pic9nko +9dRRw/H90EtNJU17/qN9O3Wv1U8gtsxV+9keHicOhNlI4tBDOhhq5YCRtKXr8WXIqb9 tDkfu0PJE8jQl3NP/1KKGTNLolCjwFXAAq1iyB7s24NeG15+zwtwbiWtBhTGtaxWD1z/ ZjVk+8eBx+Ch/nV2BUIQGK9MUs/HAs2aanySQv5y3Y2DMOSONg3mxVu1BdHn+5X2dX8P iUuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=XPzkepx623Sgym/iHFmF1QLq1zKhyTuDZnMrJRtsliE=; b=TWsM9XyT7ijVyyqBGzMLQbBNdfPVgDVMaDu8OfQmGLEdOc1X8ji9nnvofmR6uZESa3 AsclRTg1nArUCp/6FV4p7FeCNVumxycxg+Og2GRc/Qqv4lzsR9+DlszQca82Fp2Rt1WW SPPA/Ec3QZ3zU06T3FnMfke04/aA48DfvNrdvXooMXOBauGX/DqE/d9Z/zvWWEmOQpWu FQWfFnFUB84XLjpuc53UA1N+SwDvIwaM9hRC1wTYltm9WfrCVoQNszU8IZfqCnYgUwN4 ghTpnxhX3r7xM/fRMZC66tVlb0hAbfk2S12K+OseMu8O0q3IpSjOdCEbl2SEALx749au JgFA== X-Gm-Message-State: APjAAAWW+Rdo4+bGQoSw4yPLT3tWePTQWIaslYyL0NQTodhLJNBFpihh gmxOFy0rlgb664ILnU/QgTtAY2u8 X-Google-Smtp-Source: APXvYqw0530FGNMwGZ6ktJrEfJVt5H+buGuvRfHThkDKnnglJ50khvCGilVzUbW5QFcFA1hWtUmL3A== X-Received: by 2002:a1c:751a:: with SMTP id o26mr82934250wmc.13.1564134920866; Fri, 26 Jul 2019 02:55:20 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::330 X-Mailman-Approved-At: Fri, 26 Jul 2019 09:52:41 -0400 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <73adb906-3594-8c38-c820-2bf00b295e22@gmail.com> Xref: csiph.com gnu.bash.bug:15249 While handling some big strings, I noticed that bash is a lot slower than other shells like dash, posh and busybox ash. I came up with the following little benchmark and results. While the specific benchmark isn't important, maybe some developer would like to use it to pinpoint and optimize some internal bash function that is a lot slower than in other shells? # Avoid UTF-8 complications export LANG=C # Run the following COMMANDs with `time bash -c` # or `time busybox ash -c` # The time columns are in seconds, on an i5-4440 CPU ASH BASH COMMAND 0.1 0.1 printf "%100000000s" "." >/dev/null 0.7 1.1 x=$(printf "%100000000s" ".") 0.8 2.4 x=$(printf "%100000000s" "."); echo ${#x} 0.9 3.7 x=$(printf "%100000000s" "."); echo ${#x}; echo ${#x} At this point I think it's safe to assume that just calculating the 100MB string length in bash needs 1.3 secs, while in ash 0.1 secs. Similar differences may be observed in simple assignments like y=$i$x. If anyone replies, please CC me as I'm not in the list. Thanks, Alkis Georgopoulos