News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Hasin Hayder's Blog:
Counting occurrence of a word in a String - Benchmarking of PHP functions
April 30, 2007 @ 10:42:00

In an effort to add to the ever-growing list of "keeping it simple" benchmarks out there, Hasin Hayder presents his own results for the task of fining the number of times a word occurs in a given string.

Today I was just thinking what are the possible ways to count the occurrence of a specific word inside a string. I found some possible ways finally and I just benchmarked them. Wanna see the result?? - for sure you will find it interesting too.

Methods range from a simple split() and count() call out to using the regular expression functions to locate the matches. After running it four times (to check for accuracy), he the stats were pretty much the same. It looks like the substr+count method was the fastest overall with last place falling to the array function method.

0 comments voice your opinion now!
occurance word string function benchmark result microtime occurance word string function benchmark result microtime


blog comments powered by Disqus

Similar Posts

Rdavid.net: Test Results on Memory Usage of Zend Framework and Doctrine with APC

Andrey Hristov's Blog: Replacing mysqli's Connection, Result and Statement classes

DotVoid.com: Parsing the user agent string using PHP

Phil Sturgeon: Potential Variadic Function Syntax for PHP 5.6

Hasin Hayder's Blog: Counting occurrence of a word in a String - Benchmarking of PHP functions


Community Events





Don't see your event here?
Let us know!


podcast opinion language release api interview series library install unittest introduction laravel framework community deployment update tips symfony package zendserver

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework