<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Blog of Travis Hydzik &#187; faster</title>
	<atom:link href="http://thydzik.com/tag/faster/feed/" rel="self" type="application/rss+xml" />
	<link>http://thydzik.com</link>
	<description>random snippets and information</description>
	<lastBuildDate>Mon, 30 Apr 2012 15:46:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Visual Basic 6 &#8211; quickest way to find first/last character in string</title>
		<link>http://thydzik.com/visual-basic-6-quickest-way-to-find-firstlast-character-in-string/</link>
		<comments>http://thydzik.com/visual-basic-6-quickest-way-to-find-firstlast-character-in-string/#comments</comments>
		<pubDate>Fri, 29 Oct 2010 09:32:20 +0000</pubDate>
		<dc:creator>thydzik</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[compare]]></category>
		<category><![CDATA[faster]]></category>
		<category><![CDATA[InStrRev]]></category>
		<category><![CDATA[optimise]]></category>
		<category><![CDATA[Right]]></category>
		<category><![CDATA[StrComp]]></category>
		<category><![CDATA[strings]]></category>

		<guid isPermaLink="false">http://thydzik.com/?p=550</guid>
		<description><![CDATA[When you are parsing large amounts of data, the way you code string matching can make a huge difference. In one case I needed to find if a string was contained within quotes, here are the test results from quickest to slowest. The test situation was to find if the last character in the string [...]<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/visual-basic-6-quickest-way-to-find-firstlast-character-in-string/' addthis:title='Visual Basic 6 &#8211; quickest way to find first/last character in string ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>When you are parsing large amounts of data, the way you code string matching can make a huge difference. In one case I needed to find if a string was contained within quotes, here are the test results from quickest to slowest.</p>
<p>The test situation was to find if the last character in the string &#8216;abcdefghijklmnopqrstuvwxyz&#8217; is &#8216;z&#8217; and iterated 100000000 times.</p>
<p>First, the most intuitive which most would use.  TickCount of <strong>49546</strong>.</p>
<pre class="brush: vb; title: ; notranslate">
Right(&amp;amp;quot;abcdefghijklmnopqrstuvwxyz&amp;amp;quot;, 1) = &amp;amp;quot;z&amp;amp;quot;
</pre>
<p>Function Right takes in a Variant by default, by succeeding it with a dollar sign it accepts Strings by default. TickCount of <strong>22828</strong>, a significant saving.</p>
<pre class="brush: vb; title: ; notranslate">
Right$(&amp;amp;quot;abcdefghijklmnopqrstuvwxyz&amp;amp;quot;, 1) = &amp;amp;quot;z&amp;amp;quot;
</pre>
<p>Using the equals sign would be seem the norm, but what if the String Compare function was used. TickCount of <strong>18047</strong>.</p>
<pre class="brush: vb; title: ; notranslate">
StrComp(Right$(&amp;amp;quot;abcdefghijklmnopqrstuvwxyz&amp;amp;quot;, 1), &amp;amp;quot;z&amp;amp;quot;, vbBinaryCompare) = 0
</pre>
<p>What if Mid was used to extract the last character instead of Right. TickCount of <strong>28391</strong>.</p>
<pre class="brush: vb; title: ; notranslate">
StrComp(Mid$(&amp;amp;quot;abcdefghijklmnopqrstuvwxyz&amp;amp;quot;, Len(&amp;amp;quot;abcdefghijklmnopqrstuvwxyz&amp;amp;quot;), 1), &amp;amp;quot;z&amp;amp;quot;) = 0
</pre>
<p>Now what if we use the In String function. String length binary is faster than standard String length. TickCount of <strong>14516</strong>.</p>
<pre class="brush: vb; title: ; notranslate">
InStrRev(&amp;amp;quot;abcdefghijklmnopqrstuvwxyz&amp;amp;quot;, &amp;amp;quot;z&amp;amp;quot;, -1, vbBinaryCompare) = LenB(&amp;amp;quot;abcdefghijklmnopqrstuvwxyz&amp;amp;quot;) / 2
</pre>
<p>Finally, with out String length binary. TickCount of <strong>11312</strong>.</p>
<pre class="brush: vb; title: ; notranslate">
InStrRev(&amp;amp;quot;abcdefghijklmnopqrstuvwxyz&amp;amp;quot;, &amp;amp;quot;z&amp;amp;quot;, -1, vbBinaryCompare) = Len(&amp;amp;quot;abcdefghijklmnopqrstuvwxyz&amp;amp;quot;)
</pre>
<p><strong>So using In String Reverse is 77% faster.</strong></p>
<p>UPDATE next day: Three that I totally forgot about</p>
<p>In String starting at last character, TickCount <strong>11266</strong>.</p>
<pre class="brush: vb; title: ; notranslate">
InStr(Len(&amp;quot;abcdefghijklmnopqrstuvwxyz&amp;quot;), &amp;quot;abcdefghijklmnopqrstuvwxyz&amp;quot;, &amp;quot;z&amp;quot;, vbBinaryCompare) = Len(&amp;quot;abcdefghijklmnopqrstuvwxyz&amp;quot;)
</pre>
<p>And In String Binary which is naturally fast. TickCount <strong>6672</strong>.</p>
<pre class="brush: vb; title: ; notranslate">
InStrB(LenB(&amp;quot;abcdefghijklmnopqrstuvwxyz&amp;quot;) - 1, &amp;quot;abcdefghijklmnopqrstuvwxyz&amp;quot;, &amp;quot;z&amp;quot;, vbBinaryCompare) = LenB(&amp;quot;abcdefghijklmnopqrstuvwxyz&amp;quot;) - 1
</pre>
<p><strong>So using In String Binary is 70% faster.</strong></p>
<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/visual-basic-6-quickest-way-to-find-firstlast-character-in-string/' addthis:title='Visual Basic 6 &#8211; quickest way to find first/last character in string ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://thydzik.com/visual-basic-6-quickest-way-to-find-firstlast-character-in-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimizing/faster String Concatenation in VBA</title>
		<link>http://thydzik.com/optimizingfaster-string-concatenation-in-vba/</link>
		<comments>http://thydzik.com/optimizingfaster-string-concatenation-in-vba/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 00:12:37 +0000</pubDate>
		<dc:creator>thydzik</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[concatenation]]></category>
		<category><![CDATA[faster]]></category>
		<category><![CDATA[optimizing]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://thydzik.com/?p=248</guid>
		<description><![CDATA[There are numerous links about Visual Basic string concatenation, one particular is Microsoft&#8217;s How To Improve String Concatenation Performance. But the article is overwritten for the point it is trying to make, so I will share a simplified example. Lets say we want to perform the following concatenation: This takes approximately 6000 ticks. The faster [...]<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/optimizingfaster-string-concatenation-in-vba/' addthis:title='Optimizing/faster String Concatenation in VBA ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>There are numerous links about Visual Basic string concatenation, one particular is Microsoft&#8217;s <a title="How To Improve String Concatenation Performance" href="http://support.microsoft.com/kb/170964" target="_blank">How To Improve String Concatenation Performance</a>. But the article is overwritten for the point it is trying to make, so I will share a simplified example.</p>
<p>Lets say we want to perform the following concatenation:</p>
<pre class="brush: vb; title: ; notranslate">
Dim i As Long
Dim s As String
For i = 1 To 100000000
	s = &quot;A&quot; &amp; i &amp; &quot;B&quot;
Next i
</pre>
<p>This takes approximately 6000 ticks. The faster approach, yet more complex functionality would be as follows:</p>
<pre class="brush: vb; title: ; notranslate">
Dim sourceLength As Long
sourceLength = 1
Dim source As String
s = &quot;A B&quot;

Dim i As Long
Dim s As String
For i = 1 To 100000000
	source = CStr(i)
	If Len(source) &gt; sourceLength Then
		sourceLength = Len(source)
		s = &quot;A&quot; &amp; Space$(sourceLength) &amp; &quot;B&quot;
	End If
	Mid$(s, 2, sourceLength) = source
Next i
</pre>
<p>Which takes approximately 3700 ticks, a saving of nearly 40%.</p>
<div class="addthis_toolbox addthis_default_style addthis_" addthis:url='http://thydzik.com/optimizingfaster-string-concatenation-in-vba/' addthis:title='Optimizing/faster String Concatenation in VBA ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://thydzik.com/optimizingfaster-string-concatenation-in-vba/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Object Caching 550/552 objects using disk: basic
Content Delivery Network via t01.thydzik.com

Served from: thydzik.com @ 2012-05-23 07:44:33 -->
