<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Eight ways to speed up your shell scripts</title>
	<atom:link href="http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html/feed" rel="self" type="application/rss+xml" />
	<link>http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html</link>
	<description>Learn the UNIX/Linux command line</description>
	<lastBuildDate>Mon, 06 Jun 2011 01:35:32 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Michi</title>
		<link>http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html/comment-page-1#comment-47433</link>
		<dc:creator>Michi</dc:creator>
		<pubDate>Sat, 05 Mar 2011 17:11:47 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html#comment-47433</guid>
		<description>Cool thing.
Found one more:

$ time for i in {1..1000}; do echo a &gt;-; done
real	0m0.701s
user	0m0.043s
sys	0m0.258s

$ time for i in {1..1000}; do echo a &gt;/dev/null; done
real	0m0.063s
user	0m0.038s
sys	0m0.020s</description>
		<content:encoded><![CDATA[<p>Cool thing.<br />
Found one more:</p>
<p>$ time for i in {1..1000}; do echo a &gt;-; done<br />
real	0m0.701s<br />
user	0m0.043s<br />
sys	0m0.258s</p>
<p>$ time for i in {1..1000}; do echo a &gt;/dev/null; done<br />
real	0m0.063s<br />
user	0m0.038s<br />
sys	0m0.020s</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brock Noland</title>
		<link>http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html/comment-page-1#comment-5179</link>
		<dc:creator>Brock Noland</dc:creator>
		<pubDate>Wed, 26 Mar 2008 02:59:40 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html#comment-5179</guid>
		<description>Fixed.</description>
		<content:encoded><![CDATA[<p>Fixed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elias Pipping</title>
		<link>http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html/comment-page-1#comment-5157</link>
		<dc:creator>Elias Pipping</dc:creator>
		<pubDate>Tue, 25 Mar 2008 14:27:05 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html#comment-5157</guid>
		<description>I meant to say &#039;far less efficient&#039;, sorry.</description>
		<content:encoded><![CDATA[<p>I meant to say &#8216;far less efficient&#8217;, sorry.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brock Noland</title>
		<link>http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html/comment-page-1#comment-5154</link>
		<dc:creator>Brock Noland</dc:creator>
		<pubDate>Tue, 25 Mar 2008 13:42:51 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html#comment-5154</guid>
		<description>@Elias,

&gt; it’s more important than I would’ve thought, too, not to overuse quotes

That is &lt;b&gt;very&lt;/b&gt; interesting... I am guessing BASH checks each token to see if its quoted, if so it must remove the quotes which is the extra time were are seeing. I am not exactly sure why there would be a difference in single versus double quotes? Likely I guess because double quotes can have enclosed expressions whereas single quotes are taken literally.

&gt; Not only is the former far more efficient, it also isn’t safe for entries that contain spaces:

Good point, I did not quote the variable in my example.</description>
		<content:encoded><![CDATA[<p>@Elias,</p>
<p>> it’s more important than I would’ve thought, too, not to overuse quotes</p>
<p>That is <b>very</b> interesting&#8230; I am guessing BASH checks each token to see if its quoted, if so it must remove the quotes which is the extra time were are seeing. I am not exactly sure why there would be a difference in single versus double quotes? Likely I guess because double quotes can have enclosed expressions whereas single quotes are taken literally.</p>
<p>> Not only is the former far more efficient, it also isn’t safe for entries that contain spaces:</p>
<p>Good point, I did not quote the variable in my example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brock Noland</title>
		<link>http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html/comment-page-1#comment-5153</link>
		<dc:creator>Brock Noland</dc:creator>
		<pubDate>Tue, 25 Mar 2008 13:32:55 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html#comment-5153</guid>
		<description>From Elias via email:

Regarding:

&lt;pre&gt;
$ a=(); time for i in {0..1000}; do a=(${a[@]} $i);done; echo ${#a[@]}
real    0m3.545s
user    0m3.544s
sys     0m0.000s
1001

$ a=(); time for i in {0..1000}; do a[${#a[@]}]=$i;done; echo ${#a[@]}
real    0m0.043s
user    0m0.040s
sys     0m0.003s
1001
&lt;/pre&gt;

Not only is the former far less efficient, it also isn&#039;t safe for entries that contain spaces:

&lt;pre&gt;
$ A[0]=&#039;a b&#039;
$ A[1]=c
$ for ((i=0; i&lt;${#A[@]}; i++)); do echo ${A[$i]}; done
a b
c

$ B=(&#039;a b&#039;)
$ B=(${B[@]} c)
$ for ((i=0; i&lt;${#B[@]}; i++)); do echo ${B[$i]}; done
a
b
c

$ C=(&#039;a b&#039;)
# now with quotes!
$ C=(&quot;${C[@]}&quot; c)
$ for ((i=0; i&lt;${#C[@]}; i++)); do echo ${C[$i]}; done
a b
c
&lt;/pre&gt;

-- Elias</description>
		<content:encoded><![CDATA[<p>From Elias via email:</p>
<p>Regarding:</p>
<pre>
$ a=(); time for i in {0..1000}; do a=(${a[@]} $i);done; echo ${#a[@]}
real    0m3.545s
user    0m3.544s
sys     0m0.000s
1001

$ a=(); time for i in {0..1000}; do a[${#a[@]}]=$i;done; echo ${#a[@]}
real    0m0.043s
user    0m0.040s
sys     0m0.003s
1001
</pre>
<p>Not only is the former far less efficient, it also isn&#8217;t safe for entries that contain spaces:</p>
<pre>
$ A[0]='a b'
$ A[1]=c
$ for ((i=0; i< ${#A[@]}; i++)); do echo ${A[$i]}; done
a b
c

$ B=('a b')
$ B=(${B[@]} c)
$ for ((i=0; i<${#B[@]}; i++)); do echo ${B[$i]}; done
a
b
c

$ C=('a b')
# now with quotes!
$ C=("${C[@]}" c)
$ for ((i=0; i<${#C[@]}; i++)); do echo ${C[$i]}; done
a b
c
</pre>
<p>-- Elias</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elias Pipping</title>
		<link>http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html/comment-page-1#comment-5148</link>
		<dc:creator>Elias Pipping</dc:creator>
		<pubDate>Tue, 25 Mar 2008 12:46:52 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html#comment-5148</guid>
		<description>Hi,

it&#039;s more important than I would&#039;ve thought, too, not to overuse quotes - especially with double quotes when they&#039;re not needed:

&lt;pre&gt;
bash-3.2$ time for (( i = 0; i &lt; 100000; ++i )); do echo 1 2 3 4 5 6 &gt;/
dev/null;done
real    0m8.544s
user    0m5.845s
sys     0m2.698s

bash-3.2$ time for (( i = 0; i &lt; 100000; ++i)); do echo &#039;1&#039; &#039;2&#039; &#039;3&#039;
&#039;4&#039; &#039;5&#039; &#039;6&#039; &gt;/dev/null;done
real    0m9.003s
user    0m6.291s
sys     0m2.711s

bash-3.2$ time for (( i = 0; i &lt; 100000; ++i )); do echo &quot;1&quot; &quot;2&quot; &quot;3&quot;
&quot;4&quot; &quot;5&quot; &quot;6&quot; &gt;/dev/null;done
real    0m9.523s
user    0m6.787s
sys     0m2.730s&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>it&#8217;s more important than I would&#8217;ve thought, too, not to overuse quotes &#8211; especially with double quotes when they&#8217;re not needed:</p>
<pre>
bash-3.2$ time for (( i = 0; i < 100000; ++i )); do echo 1 2 3 4 5 6 >/
dev/null;done
real    0m8.544s
user    0m5.845s
sys     0m2.698s

bash-3.2$ time for (( i = 0; i < 100000; ++i)); do echo '1' '2' '3'
'4' '5' '6' >/dev/null;done
real    0m9.003s
user    0m6.291s
sys     0m2.711s

bash-3.2$ time for (( i = 0; i < 100000; ++i )); do echo "1" "2" "3"
"4" "5" "6" >/dev/null;done
real    0m9.523s
user    0m6.787s
sys     0m2.730s</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brock Noland</title>
		<link>http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html/comment-page-1#comment-5055</link>
		<dc:creator>Brock Noland</dc:creator>
		<pubDate>Mon, 24 Mar 2008 03:01:14 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html#comment-5055</guid>
		<description>@Elias,

Thanks for the BSD tip....I have been meaning to start up a OpenBSD and FreeBSD vmware instance.

Brock</description>
		<content:encoded><![CDATA[<p>@Elias,</p>
<p>Thanks for the BSD tip&#8230;.I have been meaning to start up a OpenBSD and FreeBSD vmware instance.</p>
<p>Brock</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brock Noland</title>
		<link>http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html/comment-page-1#comment-5053</link>
		<dc:creator>Brock Noland</dc:creator>
		<pubDate>Mon, 24 Mar 2008 02:58:54 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html#comment-5053</guid>
		<description>@Elias,

You make an excellent point. The comparisons are not the same. Not sure why I did not use &quot;let i++&quot;. With that said, ((i++)) still seems to be faster than let i++ but not by the same margin.

Brock

&lt;pre&gt;
$ i=0; time while :; do let i++; [[ $i -gt 100000 ]] &amp;&amp; break;done

real    0m5.167s
user    0m4.773s
sys     0m0.392s
$ i=0; time while :; do ((i++)); [[ $i -gt 100000 ]] &amp;&amp; break;done

real    0m4.147s
user    0m3.815s
sys     0m0.331s
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>@Elias,</p>
<p>You make an excellent point. The comparisons are not the same. Not sure why I did not use &#8220;let i++&#8221;. With that said, ((i++)) still seems to be faster than let i++ but not by the same margin.</p>
<p>Brock</p>
<pre>
$ i=0; time while :; do let i++; [[ $i -gt 100000 ]] &#038;& break;done

real    0m5.167s
user    0m4.773s
sys     0m0.392s
$ i=0; time while :; do ((i++)); [[ $i -gt 100000 ]] &#038;& break;done

real    0m4.147s
user    0m3.815s
sys     0m0.331s
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elias Pipping</title>
		<link>http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html/comment-page-1#comment-5047</link>
		<dc:creator>Elias Pipping</dc:creator>
		<pubDate>Mon, 24 Mar 2008 00:31:27 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html#comment-5047</guid>
		<description>Hi,

On BSD systems, jot(1) is faster than List expansion.

bash-3.2$ time for i in `jot 1000001 0`; do :; done
real	0m8.765s
user	0m8.799s
sys	0m0.187s

bash-3.2$ time for i in {0..1000000}; do :; done
real	0m9.411s
user	0m9.346s
sys	0m0.053s

PS: naturally, using jot(1) doesn&#039;t exactly make a script portable since it won&#039;t work on, say, linux, but then again using seq(1) would break the script on BSD...</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>On BSD systems, jot(1) is faster than List expansion.</p>
<p>bash-3.2$ time for i in `jot 1000001 0`; do :; done<br />
real	0m8.765s<br />
user	0m8.799s<br />
sys	0m0.187s</p>
<p>bash-3.2$ time for i in {0..1000000}; do :; done<br />
real	0m9.411s<br />
user	0m9.346s<br />
sys	0m0.053s</p>
<p>PS: naturally, using jot(1) doesn&#8217;t exactly make a script portable since it won&#8217;t work on, say, linux, but then again using seq(1) would break the script on BSD&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elias Pipping</title>
		<link>http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html/comment-page-1#comment-5045</link>
		<dc:creator>Elias Pipping</dc:creator>
		<pubDate>Mon, 24 Mar 2008 00:19:00 +0000</pubDate>
		<guid isPermaLink="false">http://bashcurescancer.com/six-ways-to-speed-up-your-shell-scripts.html#comment-5045</guid>
		<description>Hi,

in &quot;Arithmetic Evaluation is faster than let&quot; you&#039;re comparing

$ i=0; time while :; do let &quot;i = i + 1&quot;; [[ $i -gt 100000 ]] &amp;&amp; break;done

and

$ i=0; time while :; do ((i++)); [[ $i -gt 100000 ]] &amp;&amp; break;done

That&#039;s not really &quot;Arithmetic Evaluation vs. let&quot;, though, because the former can be written as

$ i=0; time while :; do let i++; [[ $i -gt 100000 ]] &amp;&amp; break;done

resulting in mostly the same speed. So what&#039;s slow here is really

((i++)) vs. ((i=i+1)) or `let i++` vs. `let i=i+1`</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>in &#8220;Arithmetic Evaluation is faster than let&#8221; you&#8217;re comparing</p>
<p>$ i=0; time while :; do let &#8220;i = i + 1&#8243;; [[ $i -gt 100000 ]] &amp;&amp; break;done</p>
<p>and</p>
<p>$ i=0; time while :; do ((i++)); [[ $i -gt 100000 ]] &amp;&amp; break;done</p>
<p>That&#8217;s not really &#8220;Arithmetic Evaluation vs. let&#8221;, though, because the former can be written as</p>
<p>$ i=0; time while :; do let i++; [[ $i -gt 100000 ]] &amp;&amp; break;done</p>
<p>resulting in mostly the same speed. So what&#8217;s slow here is really</p>
<p>((i++)) vs. ((i=i+1)) or `let i++` vs. `let i=i+1`</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.221 seconds -->

