[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] What is the best way to push back an element to address@hidd
From: |
Peng Yu |
Subject: |
[Help-bash] What is the best way to push back an element to address@hidden |
Date: |
Sun, 17 Apr 2016 09:49:28 -0500 |
Hi, I currently use following two ways (1. cmd1& set -- "address@hidden", 2.
cmd2) to push back to address@hidden
Obviously, way 1 is faster, because it will append each element to the
end of the array a, which presumably is independent of the size of the
array a. The drawback is that it involves the temp array a.
Way 2 is much slower, because I understand that the time to add an
element to $@ will increase as the size of $@ increases.
What is best way to push back an element to address@hidden Does anybody have a
suggestion?
input=($(seq 1000))
function cmd1 {
for x in "address@hidden"
do
a+=("$x")
done
}
function cmd2 {
for x in "address@hidden"
do
set -- "$@" "$x"
done
}
bash> cmd
real 0m0.036s
user 0m0.018s
sys 0m0.012s
bash> set -- "address@hidden"
real 0m0.029s
user 0m0.012s
sys 0m0.012s
bash> cmd2
real 0m1.195s
user 0m1.178s
sys 0m0.012s
--
Regards,
Peng
- [Help-bash] What is the best way to push back an element to address@hidden,
Peng Yu <=