summaryrefslogtreecommitdiff
path: root/_test/cases
diff options
context:
space:
mode:
authorYoBoY <yoboy.leguesh@gmail.com>2010-03-23 22:50:41 +0100
committerAndreas Gohr <andi@splitbrain.org>2010-03-24 21:27:23 +0100
commit229529655f061863ec76db9ea557fef8b1a5161b (patch)
treea0363b7385e7a2e4f16e4c3bb65e1ee1475d2108 /_test/cases
parent3371a8b471eea344a99f015cdf0ef9089b1f20ef (diff)
downloadrpg-229529655f061863ec76db9ea557fef8b1a5161b.tar.gz
rpg-229529655f061863ec76db9ea557fef8b1a5161b.tar.bz2
Limiting use of readdir in the idx_indexLengths function (v2).
Each searches on the wiki use this function. Scanning the index directory eachtime is time consuming with a constant series of disk access. Switching a normal search to use file_exists 1 or more times, and not readdir all the directory. Switching a wildcard search to use a lengths.idx file containing all the word lengths used in the wiki, file generated if a new configuration parameter $conf[readdircache] is not 0 and fixed to a time in second. Creation of a new function idx_listIndexLengths to do this part.
Diffstat (limited to '_test/cases')
-rw-r--r--_test/cases/inc/indexer_idx_indexlengths.test.php121
1 files changed, 121 insertions, 0 deletions
diff --git a/_test/cases/inc/indexer_idx_indexlengths.test.php b/_test/cases/inc/indexer_idx_indexlengths.test.php
new file mode 100644
index 000000000..d1339a111
--- /dev/null
+++ b/_test/cases/inc/indexer_idx_indexlengths.test.php
@@ -0,0 +1,121 @@
+<?php
+
+require_once DOKU_INC.'inc/indexer.php';
+
+class indexer_idx_indexlengths_test extends UnitTestCase {
+
+ /**
+ * Test the function with an array of one value
+ */
+ function test_oneWord(){
+ global $conf;
+ $filter[8] = array('dokuwiki');
+ // one word should return the index
+ $ref[] = 8;
+ sort($ref);
+ $result = idx_indexLengths(&$filter);
+ sort($result);
+ $this->assertIdentical($result, $ref);
+ }
+
+ /**
+ * Test the function with an array of values
+ */
+ function test_moreWords() {
+ global $conf;
+ $filter = array( 4 => array('test'), 8 => array('dokuwiki'), 7 => array('powered'));
+ // more words should return the indexes
+ $ref = array(4, 7, 8);
+ sort($ref);
+ $result = idx_indexLengths(&$filter);
+ sort($result);
+ $this->assertIdentical($result, $ref);
+ }
+
+ /**
+ * Test a minimal value in case of wildcard search
+ */
+ function test_minValue() {
+ global $conf;
+ $filter = 5;
+ // construction of the list of the index to compare
+ $dir = @opendir($conf['indexdir']);
+ $ref = array();
+ while (($f = readdir($dir)) !== false) {
+ if (substr($f,0,1) == 'i' && substr($f,-4) == '.idx'){
+ $i = substr($f,1,-4);
+ if (is_numeric($i) && $i >= $filter)
+ $ref[] = (int)$i;
+ }
+ }
+ closedir($dir);
+ sort($ref);
+ $result = idx_indexLengths(&$filter);
+ sort($result);
+ $this->assertIdentical($result, $ref);
+ }
+}
+
+class indexer_idx_indexlengths_time extends UnitTestCase {
+
+ /**
+ * Test the time improvments of the new function
+ * Time reference for 10000 call oneWords: 4,6s
+ * It's 90% faster
+ */
+ function test_oneWord(){
+ global $conf;
+ $filter[8] = array('dokuwiki');
+ $start = microtime(true);
+ for ($i = 0; $i < 10000; $i++) {
+ $result = idx_indexLengths(&$filter);
+ }
+ $end = microtime(true);
+ $time = $end - $start;
+ $timeref = 4.6*0.10; // actual execution time of 4,6s for 10000 calls
+ echo "1) 10% ref : $timeref -> $time \n";
+ $this->assertTrue($time < $timeref);
+ }
+
+ /**
+ * Test the time improvments of the new function
+ * Time reference for 10000 call moreWords: 4,6s
+ * It's 90% faster
+ */
+ function test_moreWords() {
+ global $conf;
+ $filter = array( 4 => array('test'), 8 => array('dokuwiki'), 7 => array('powered'));
+ // more words should return the indexes
+ $start = microtime(true);
+ for ($i = 0; $i < 10000; $i++) {
+ $result = idx_indexLengths(&$filter);
+ }
+ $end = microtime(true);
+ $time = $end - $start;
+ $timeref = 4.6*0.10; // actual execution time of 4,6s for 10000 calls
+ echo "2) 10% ref : $timeref -> $time \n";
+ $this->assertTrue($time < $timeref);
+ }
+
+ /**
+ * Test the time improvments of the new function
+ * Time reference for 10000 call on minValue: 4,9s
+ * Sould be at least 65% faster
+ * Test fail with no cache
+ */
+ function test_minValue() {
+ global $conf;
+ $filter = 5;
+ $start = microtime(true);
+ for ($i = 0; $i < 10000; $i++) {
+ $result = idx_indexLengths(&$filter);
+ }
+ $end = microtime(true);
+ $time = $end - $start;
+ $timeref = 4.9 * 0.35; // actual execution time of 4,9s for 10000 calls
+ echo "3) 35% ref : $timeref -> $time \n";
+ $this->assertTrue($time < $timeref);
+ }
+}
+
+//Setup VIM: ex: et ts=4 enc=utf-8 :