<?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>高速化 | ウダ2Blog</title>
	<atom:link href="https://uda2.com/blog/tag/%e9%ab%98%e9%80%9f%e5%8c%96/feed/" rel="self" type="application/rss+xml" />
	<link>https://uda2.com/blog</link>
	<description>大阪でフリーランスとしてWEB制作している管理人が気になった技術をメモったり、作ったツールの紹介などを綴っているブログです。</description>
	<lastBuildDate>Thu, 17 Apr 2014 11:53:46 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>○○で始まる文字列検索の速度比較</title>
		<link>https://uda2.com/blog/phpstrspeed/</link>
					<comments>https://uda2.com/blog/phpstrspeed/#respond</comments>
		
		<dc:creator><![CDATA[uda2]]></dc:creator>
		<pubDate>Thu, 17 Apr 2014 11:53:46 +0000</pubDate>
				<category><![CDATA[制作日記]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[高速化]]></category>
		<guid isPermaLink="false">http://uda2.com/blog/?p=1480</guid>

					<description><![CDATA[<p>PHPにて「○○で始まる文字列」を検索する場合、一番に思いつくのは正規表現だけど重いのでstrposで検索していたがstrposは検索位置を返すし全体を検索するのでなんとなく遅いかなと思い別の方法を模索してみた。 PHP</p>
The post <a href="https://uda2.com/blog/phpstrspeed/">○○で始まる文字列検索の速度比較</a> first appeared on <a href="https://uda2.com/blog">ウダ2Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>PHPにて「○○で始まる文字列」を検索する場合、一番に思いつくのは正規表現だけど重いのでstrposで検索していたがstrposは検索位置を返すし全体を検索するのでなんとなく遅いかなと思い別の方法を模索してみた。</p>
<p><a href="http://selfkleptomaniac.org/archives/45" target="_blank">PHPのパフォーマンス改善(3) | Selfkleptomaniac</a><br />
という記事にstrncmpを含んだ3つの方法が書かれていたので計5つの方法のベンチを取って比較してみた。<br />
（各秒数は約8万行を検索したしたベンチの10回分の平均値。）</p>
<p>strncmp版（先頭から特定文字数分検索する関数）<br />
if (!strncmp($myvalue, $searchstr, 5)) ～<br />
0.0312 sec</p>
<p>substr版（文字列を部分抽出する関数）<br />
if (substr($myvalue, 0, 5) == $searchstr) ～<br />
0.0447 sec</p>
<p>preg_match版（正規表現を利用した検索）<br />
if (preg_match(&#8216;!^&#8217;.$searchstr.&#8217;!&#8217;, $myvalue)) ～<br />
0.0578 sec </p>
<p>substr_compare版（特定部分から特定文字数分検索する関数）<br />
if (substr_compare($myvalue, $searchstr, 0, 5) == 0) ～<br />
0.0415 sec </p>
<p>strpos版（文字列の開始位置を検索する関数）<br />
if (strpos($myvalue, $searchstr) === 0) ～<br />
0.0297 sec </p>
<p>おっしゃる通り「strncmp」は速く「preg_match」は遅いが「strpos」が予想以上に速く、<a href="http://uda2.com/blog/2007/07/post_5/" target="_blank">単純な文字列の検索</a>も今回のような特定位置の文字列検索も「strpos」が最速という結果になった。</p>The post <a href="https://uda2.com/blog/phpstrspeed/">○○で始まる文字列検索の速度比較</a> first appeared on <a href="https://uda2.com/blog">ウダ2Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://uda2.com/blog/phpstrspeed/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
