. /** * Media filter performance test script. * * For developer test usage only. This can be used to compare performance if * there are changes to the system in future. * * @copyright 2012 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @package filter_mediaplugin */ require(dirname(__FILE__) . '/../../../config.php'); require_once($CFG->dirroot . '/filter/mediaplugin/filter.php'); // Only available to site admins. require_login(); if (!is_siteadmin()) { print_error('nopermissions', 'error', '', 'perftest'); } // Set up page. $PAGE->set_context(context_system::instance()); $PAGE->set_url(new moodle_url('/filter/mediaplugin/perftest.php')); $PAGE->set_heading($SITE->fullname); print $OUTPUT->header(); // Hack setup to enable all players. $CFG->core_media_enable_youtube = 1; $CFG->core_media_enable_vimeo = 1; $CFG->core_media_enable_mp3 = 1; $CFG->core_media_enable_flv = 1; $CFG->core_media_enable_swf = 1; $CFG->core_media_enable_html5audio = 1; $CFG->core_media_enable_html5video = 1; $CFG->core_media_enable_qt = 1; $CFG->core_media_enable_wmp = 1; $CFG->core_media_enable_rm = 1; $CFG->filter_mediaplugin_enable_youtube = 1; $CFG->filter_mediaplugin_enable_vimeo = 1; $CFG->filter_mediaplugin_enable_mp3 = 1; $CFG->filter_mediaplugin_enable_flv = 1; $CFG->filter_mediaplugin_enable_swf = 1; $CFG->filter_mediaplugin_enable_html5audio = 1; $CFG->filter_mediaplugin_enable_html5video = 1; $CFG->filter_mediaplugin_enable_qt = 1; $CFG->filter_mediaplugin_enable_wmp = 1; $CFG->filter_mediaplugin_enable_rm = 1; // Create plugin. $filterplugin = new filter_mediaplugin(null, array()); // Note: As this is a developer test page, language strings are not used: all // text is English-only. /** * Starts time counter. */ function filter_mediaplugin_perf_start() { global $filter_mediaplugin_starttime; $filter_mediaplugin_starttime = microtime(true); } /** * Ends and displays time counter. * @param string $name Counter name to display */ function filter_mediaplugin_perf_stop($name) { global $filter_mediaplugin_starttime; $time = microtime(true) - $filter_mediaplugin_starttime; echo html_writer::tag('li', $name . ': ' . html_writer::tag('strong', round($time, 2)) . 'ms'); } // 1) Some sample text strings. // Note: These are from a random sample of real forum data. Just in case there // are any privacy concerns I have altered names as may be clear. $samples = array( "
Hi,
\nI've got myself 2 Heaney's \"The Burial at Thebes\"
", "best mark iv heard so far v v good", "I have a script draft anyone want to look at it?", "
Thanks for your input Legolas and Ghimli!
", "Just to say that I'm thinking of those of you who are working on TMA02.
", "1. If someone asks you 'where do you come from?'
", "With regards to Aragorn's question 'what would we do different'?
\n", "Just thought I'd drop a line to see how everyone is managing generally?
\n", "Feb '12 - Oct '12 AA100
\nNov '12 - April '13 - A150
\n", "So where does that leave the bible???
", ); // 2) Combine sample text strings into one really big (20KB) string. $length = 0; $bigstring = ''; $index = 0; while ($length < 20 * 1024) { $bigstring .= $samples[$index]; $length += strlen($samples[$index]); $index++; if ($index >= count($samples)) { $index = 0; } } // 3) Make random samples from this. I did the following stats on recent forum // posts: // 0-199 characters approx 30% // 200-1999 approx 60% // 2000-19999 approx 10%. $samplebank = array(); foreach (array(100 => 300, 1000 => 600, 10000 => 100) as $chars => $num) { for ($i = 0; $i < $num; $i++) { $start = rand(0, $length - $chars - 1); $samplebank[] = substr($bigstring, $start, $chars); } } echo html_writer::start_tag('ul'); // First test: filter text that doesn't have any links. filter_mediaplugin_perf_start(); foreach ($samplebank as $sample) { $filterplugin->filter($sample); } filter_mediaplugin_perf_stop('No links'); // Second test: filter text with one link added (that doesn't match). $link = 'Link'; $linksamples = array(); foreach ($samplebank as $sample) { // Make it the same length but with $link replacing the end part. $linksamples[] = substr($sample, 0, -strlen($link)) . $link; } filter_mediaplugin_perf_start(); foreach ($linksamples as $sample) { $filterplugin->filter($sample); } filter_mediaplugin_perf_stop('One link (no match)'); // Third test: filter text with one link added that does match (mp3). $link = 'MP3 audio'; $linksamples = array(); foreach ($samplebank as $sample) { // Make it the same length but with $link replacing the end part. $linksamples[] = substr($sample, 0, -strlen($link)) . $link; } filter_mediaplugin_perf_start(); foreach ($linksamples as $sample) { $filterplugin->filter($sample); } filter_mediaplugin_perf_stop('One link (mp3)'); // End page. echo html_writer::end_tag('ul'); print $OUTPUT->footer();