11
|
1 #!/usr/bin/perl -w
|
18
|
2 use strict;
|
36
|
3 use lib '..\Lib';
|
11
|
4
|
36
|
5 require IMPL::DOM::Navigator::SimpleBuilder;
|
37
|
6 require IMPL::DOM::XMLReader;
|
11
|
7
|
36
|
8 my $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
|
|
9
|
|
10 use Time::HiRes qw(gettimeofday tv_interval);
|
|
11
|
|
12 my $t = [gettimeofday];
|
|
13
|
|
14 $builder->NavigateCreate('personInfo', version => '1');
|
|
15 $builder->NavigateCreate('firstName')->nodeValue('Nemo');
|
|
16 $builder->Back();
|
|
17 $builder->NavigateCreate('lastName')->nodeValue('Nobel');
|
|
18 $builder->Back();
|
|
19 $builder->NavigateCreate('lastName')->nodeValue('Gardum');
|
|
20 $builder->Back();
|
37
|
21 for(my $i = 0 ; $i < 10000; $i++) {
|
36
|
22 $builder->NavigateCreate('address', local => 1);
|
|
23 $builder->NavigateCreate('street')->nodeValue('Hellroad');
|
|
24 $builder->Back();
|
|
25 $builder->NavigateCreate('line')->nodeValue($_);
|
|
26 $builder->Back();
|
|
27 $builder->Back();
|
|
28 }
|
|
29 $builder->Back();
|
|
30
|
37
|
31 print "Build: ",tv_interval($t,[gettimeofday]),"\n";
|
|
32
|
|
33 $t = [gettimeofday];
|
|
34
|
|
35 my $doc = new IMPL::DOM::Document(nodeName => 'doc');
|
|
36 for(my $i = 0 ; $i < 30000; $i++) {
|
|
37 my $node = new IMPL::DOM::Node(nodeName => 'test');
|
|
38 $node->nodeValue(100);
|
|
39 $doc->appendChild($node);
|
|
40 }
|
|
41
|
|
42 print "Create 30000 nodes: ",tv_interval($t,[gettimeofday]),"\n";
|
|
43
|
|
44 $t = [gettimeofday];
|
|
45 $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
|
|
46 my $reader = IMPL::DOM::XMLReader->new( Navigator => $builder );
|
|
47
|
|
48 $reader->ParseFile("Resources/large.xml");
|
|
49 print "Parsing large Xml file: ",tv_interval($t,[gettimeofday]),"\n";
|
|
50
|
|
51 my $count = selectAll($builder->Document);
|
|
52 my $len = length $builder->Document->text;
|
|
53 print "Total nodes loaded: $count, data length: $len\n";
|
|
54
|
|
55 $t = [gettimeofday];
|
|
56 $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
|
|
57 my $reader2 = IMPL::DOM::XMLReader->new( Navigator => $builder );
|
|
58
|
|
59 $reader2->ParseFile("Resources/person_info.xml");
|
|
60 print "Parsing small Xml file: ",tv_interval($t,[gettimeofday]),"\n";
|
|
61
|
|
62 sub selectAll {
|
|
63 my $node = shift;
|
|
64 $node,map selectAll($_),@{$node->childNodes};
|
|
65 } |