bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

a very slow problem of replacing string


From: sky
Subject: a very slow problem of replacing string
Date: Thu, 23 Sep 2010 22:12:28 +0900

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-redhat-linux-gnu'
-DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale'
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include
-I./lib  -D_GNU_SOURCE -DRECYCLES_PIDS  -O2 -g -pipe -Wall
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m64 -mtune=generic
uname output: Linux fedora14 2.6.35-0.57.rc6.git1.fc14.x86_64 #1 SMP
Mon Jul 26 22:43:02 UTC 2010 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-redhat-linux-gnu

Bash Version: 4.1
Patch Level: 7
Release Status: release

Description:
        I am a programmer working in Japan.
        I encountered a very slow problem of replacing string in one
of my script. I hope to be fixed in the future release. I attach a
sample script of the essence.
--- cut here ---
#!/bin/bash
# str_replace_perf.bash

#
# prepare 1000 strings of 6 digits
#
TEST_LIST=`seq 100100 100 200000`
echo $TEST_LIST | wc

#
# delete "150000"
#
T0=$SECONDS
A=${TEST_LIST//150000}
T1=$SECONDS
B=`echo $TEST_LIST | sed s/150000//g`
T2=$SECONDS

#
# results
#
echo T1-T0=$((T1-T0))
echo T2-T1=$((T2-T1))

# verify
echo $A | md5sum
echo $B | md5sum
----------------

Repeat-By:
        Please run 'str_replace_perf.bash' .
        The next is a result on my machine.

# ./str_replace_perf.bash
      1    1000    7000
T1-T0=10
T2-T1=0
de028ddb26bdd0b5aa062b1b8e753665  -
de028ddb26bdd0b5aa062b1b8e753665  -

        I recognized that
        current Bash's ${TEST_LIST//150000} syntax is very slow.
        I hope to be improved in the future.

Best Regards,
s-taka (Satoshi Takahashi) - this is my name.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]