Skip to content

Commit

Permalink
MDL-38698 filter_urltolink: Remove performance test in Unit Test
Browse files Browse the repository at this point in the history
  • Loading branch information
FMCorz committed Dec 17, 2013
1 parent e158787 commit 850db41
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions filter/urltolink/tests/filter_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,6 @@

class filter_urltolink_testcase extends basic_testcase {

/**
* Helper function that represents the legacy implementation
* of convert_urls_into_links()
*/
protected function old_convert_urls_into_links(&$text) {
/// Make lone URLs into links. eg http://moodle.com/
$text = preg_replace("%([[:space:]]|^|\(|\[)([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])%i",
'$1<a href="$2://$3$4" target="_blank">$2://$3$4</a>', $text);
/// eg www.moodle.com
$text = preg_replace("%([[:space:]]|^|\(|\[)www\.([^[:space:]]*)([[:alnum:]#?/&=])%i",
'$1<a href="http://www.$2$3" target="_blank">www.$2$3</a>', $text);
}

function get_convert_urls_into_links_test_cases() {
$texts = array (
//just a url
Expand Down Expand Up @@ -186,32 +173,6 @@ function test_convert_urls_into_links($text, $correctresult) {
$this->assertEquals($correctresult, $text);
}

function test_convert_urls_into_links_performance() {
$testablefilter = new testable_filter_urltolink();

$reps = 1000;
$text = file_get_contents(__DIR__ . '/fixtures/sample.txt');
$time_start = microtime(true);
for($i=0;$i<$reps;$i++) {
$testablefilter->convert_urls_into_links($text);
}
$time_end = microtime(true);
$new_time = $time_end - $time_start;

$time_start = microtime(true);
for($i=0;$i<$reps;$i++) {
$this->old_convert_urls_into_links($text);
}
$time_end = microtime(true);
$old_time = $time_end - $time_start;

$fast_enough = false;
if( $new_time < $old_time ) {
$fast_enough = true;
}

$this->assertEquals($fast_enough, true, 'Timing test: ' . $new_time . 'secs (new) < ' . $old_time . 'secs (old)');
}
}


Expand Down

0 comments on commit 850db41

Please sign in to comment.