/
ParserPerformance.php
68 lines (57 loc) · 1.67 KB
/
ParserPerformance.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
set_include_path(
get_include_path() . PATH_SEPARATOR .
dirname(__FILE__) . '/../lib/'
);
require_once "EasyRdf.php";
$parsers = array(
'Arc',
'Json',
'Ntriples',
'RdfXml',
'Rapper',
'Redland',
);
$documents = array(
'foaf.rdf' => 'rdfxml',
'foaf.ttl' => 'turtle',
'foaf.nt' => 'ntriples',
'foaf.json' => 'json',
'dundee.rdf' => 'rdfxml',
'dundee.ttl' => 'turtle',
'dundee.nt' => 'ntriples',
'dundee.json' => 'json',
'london.rdf' => 'rdfxml',
'london.ttl' => 'turtle',
'london.nt' => 'ntriples',
'london.json' => 'json',
);
foreach ($documents as $filename => $type) {
print "Input file: $filename\n";
$filepath = dirname(__FILE__) . "/performance/$filename";
if (!file_exists($filepath)) {
print "Error: File does not exist.\n";
continue;
}
$url = "http://www.example.com/$filename";
$data = file_get_contents($filepath);
print "File size: ".strlen($data)." bytes\n";
foreach ($parsers as $parser_name) {
$class = "EasyRdf_Parser_$parser_name";
print " Parsing using: $class\n";
try {
require_once "EasyRdf/Parser/$parser_name.php";
$parser = new $class();
$graph = new EasyRdf_Graph();
$start = microtime(true);
$parser->parse($graph, $data, $type, $url);
$duration = microtime(true) - $start;
print " Parse time: $duration seconds\n";
print " Triple count: ".$graph->countTriples()."\n";
} catch (Exception $e) {
print 'Parsing failed: '.$e->getMessage()."\n";
}
print "\n";
unset($graph);
}
}