Processing the same text over-and-over is not a good idea. Just process it once and store it.
class TextStatistics {
protected $text;
protected $strEncoding = ''; // Used to hold character encoding to be used by object, if set
/**
* Constructor.
*
* @param string $strEncoding Optional character encoding.
* @return void
*/
public function __construct($text = NULL) {
if($text) {
$this->setText($text);
}
}
/**
* Set the text to parse
*/
public function setText($text) {
$this->strEncoding = mb_detect_encoding($text);
$this->text = $this->clean_text($text);
}
/**
* Fetch the current object text
*/
public function getText() {
return $this->text;
}
/**
* Fetch the current object encoding
*/
public function getEncoding() {
return $this->strEncoding;
}
/**
* Gives the Flesch-Kincaid Reading Ease of text entered rounded to one digit
* @param strText Text to be checked
*/
public function flesch_kincaid_reading_ease() {
$strText = $this->text;
....
After making this simple change the processing time for me on a small document dropped from 0.16 seconds to 0.11 seconds do to the reduced clean_text calls.
Processing the same text over-and-over is not a good idea. Just process it once and store it.
....
After making this simple change the processing time for me on a small document dropped from 0.16 seconds to 0.11 seconds do to the reduced clean_text calls.