Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: text/html; charset=UTF-8');
- error_reporting(E_ALL ^ E_NOTICE);
- require 'benchmark.php';
- function regex($text) {
- $pattern = '/<a\shref=["\']([^"]+)["\']/i';
- preg_match_all($pattern, $text, $matches);
- return $matches[1];
- }
- function domdocument($text) {
- // Create a new DOM Document to hold our webpage structure
- $dom = new DOMDocument();
- // Load the url's contents into the DOM
- @$dom->loadHTML($text);
- // Empty array to hold all links to return
- $links = array();
- //Loop through each <a> tag in the dom and add it to the link array
- foreach ($dom->getElementsByTagName('a') as $link) {
- $links[] = $link->getAttribute('href');
- }
- return $links;
- }
- function curl_open($url) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_FAILONERROR, true);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)');
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
- $subject = curl_open('http://pl.wikipedia.org/wiki/Polska');
- $result = array();
- $result[1]['reg'] = Benchmark('regex', 1, $subject);
- $result[1]['dom'] = Benchmark('domdocument', 1, $subject);
- $result[10]['reg'] = Benchmark('regex', 10, $subject);
- $result[10]['dom'] = Benchmark('domdocument', 10, $subject);
- $result[100]['reg'] = Benchmark('regex', 100, $subject);
- $result[100]['dom'] = Benchmark('domdocument', 100, $subject);
- $result[1000]['reg'] = Benchmark('regex', 1000, $subject);
- $result[1000]['dom'] = Benchmark('domdocument', 1000, $subject);
- echo '<pre>';
- print_r ($result);
- echo '</pre>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement