comparison _test/Test/DOM/Builder.pm @ 37:c2e7f7c96bcd

performance improvements, DOM reworked (a little)
author Sergey
date Mon, 23 Nov 2009 00:59:06 +0300
parents 1828103371d0
children 16ada169ca75
comparison
equal deleted inserted replaced
36:1828103371d0 37:c2e7f7c96bcd
10 10
11 require IMPL::DOM::Schema; 11 require IMPL::DOM::Schema;
12 require IMPL::DOM::Navigator::Builder; 12 require IMPL::DOM::Navigator::Builder;
13 require IMPL::DOM::Navigator::SimpleBuilder; 13 require IMPL::DOM::Navigator::SimpleBuilder;
14 require IMPL::DOM::Document; 14 require IMPL::DOM::Document;
15 require IMPL::DOM::XMLReader;
15 16
16 BEGIN { 17 BEGIN {
17 public property schemaDoc => prop_all; 18 public property schemaDoc => prop_all;
18 } 19 }
19 20
54 my $builder = IMPL::DOM::Navigator::Builder->new( 55 my $builder = IMPL::DOM::Navigator::Builder->new(
55 'IMPL::DOM::Document', 56 'IMPL::DOM::Document',
56 $this->schemaDoc 57 $this->schemaDoc
57 ); 58 );
58 59
59 use Time::HiRes qw(gettimeofday tv_interval);
60
61 my $t = [gettimeofday];
62
63 $builder->NavigateCreate('personInfo', version => '1'); 60 $builder->NavigateCreate('personInfo', version => '1');
64 $builder->NavigateCreate('firstName')->nodeValue('Nemo'); 61 $builder->NavigateCreate('firstName')->nodeValue('Nemo');
65 $builder->Back(); 62 $builder->Back();
66 $builder->NavigateCreate('lastName')->nodeValue('Nobel'); 63 $builder->NavigateCreate('lastName')->nodeValue('Nobel');
67 $builder->Back(); 64 $builder->Back();
68 $builder->NavigateCreate('lastName')->nodeValue('Gardum'); 65 for(1..10) {
69 $builder->Back();
70 for(1..100) {
71 $builder->NavigateCreate('address', local => 1); 66 $builder->NavigateCreate('address', local => 1);
72 $builder->NavigateCreate('street')->nodeValue('Hellroad'); 67 $builder->NavigateCreate('street')->nodeValue('Hellroad');
73 $builder->Back(); 68 $builder->Back();
74 $builder->NavigateCreate('line')->nodeValue($_); 69 $builder->NavigateCreate('line')->nodeValue($_);
75 $builder->Back(); 70 $builder->Back();
76 $builder->Back(); 71 $builder->Back();
77 } 72 }
78 $builder->Back(); 73 $builder->Back();
79 74
80 print "Build: ",tv_interval($t,[gettimeofday]),"\n"; 75 my @errors = $this->schemaDoc->Validate($builder->Document);
81 $t = [gettimeofday]; 76 failed ("The built document doesn't pass a validation",@errors) if @errors;
82 print $_->Message,"\n" foreach $this->schemaDoc->Validate($builder->Document);
83 print "Validate: ",tv_interval($t,[gettimeofday]),"\n";
84 77
85 return 1; 78 return 1;
86 }; 79 };
87 80
88 test BuildSimpleDocument => sub { 81 test BuildSimpleDocument => sub {
89 my ($this) = @_; 82 my ($this) = @_;
90 83
91 my $builder = IMPL::DOM::Navigator::SimpleBuilder->new(); 84 my $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
92 85
93 use Time::HiRes qw(gettimeofday tv_interval);
94
95 my $t = [gettimeofday];
96
97 $builder->NavigateCreate('personInfo', version => '1'); 86 $builder->NavigateCreate('personInfo', version => '1');
98 $builder->NavigateCreate('firstName')->nodeValue('Nemo'); 87 $builder->NavigateCreate('firstName')->nodeValue('Nemo');
99 $builder->Back(); 88 $builder->Back();
100 $builder->NavigateCreate('lastName')->nodeValue('Nobel'); 89 $builder->NavigateCreate('lastName')->nodeValue('Nobel');
101 $builder->Back(); 90 $builder->Back();
102 $builder->NavigateCreate('lastName')->nodeValue('Gardum'); 91 for(1..10) {
103 $builder->Back();
104 for(1..100) {
105 $builder->NavigateCreate('address', local => 1); 92 $builder->NavigateCreate('address', local => 1);
106 $builder->NavigateCreate('street')->nodeValue('Hellroad'); 93 $builder->NavigateCreate('street')->nodeValue('Hellroad');
107 $builder->Back(); 94 $builder->Back();
108 $builder->NavigateCreate('line')->nodeValue($_); 95 $builder->NavigateCreate('line')->nodeValue($_);
109 $builder->Back(); 96 $builder->Back();
110 $builder->Back(); 97 $builder->Back();
111 } 98 }
112 $builder->Back(); 99 $builder->Back();
113 100
114 print "Build: ",tv_interval($t,[gettimeofday]),"\n"; 101 my @errors = $this->schemaDoc->Validate($builder->Document);
115 $t = [gettimeofday]; 102 failed ("The built document doesn't pass a validation",@errors) if @errors;
116 print $_->Message,"\n" foreach $this->schemaDoc->Validate($builder->Document);
117 print "Validate: ",tv_interval($t,[gettimeofday]),"\n";
118
119 $t = [gettimeofday];
120 for (1...100) {
121 my $node = new IMPL::DOM::Node(nodeName => 'dummy', foo => 'bar');
122 $node->nodeValue('dummy content');
123 }
124 print "Create a set of nodes: ",tv_interval($t,[gettimeofday]),"\n";
125 103
126 return 1; 104 return 1;
127 }; 105 };
128 106
107 test BuildDocumentFromXml => sub {
108 my ($this) = @_;
109
110 my $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
111 my $reader = IMPL::DOM::XMLReader->new( Navigator => $builder );
112
113 $reader->ParseFile("Resources/person_info.xml");
114
115 my $doc = $builder->Document() or failed("No document was constrcuted");
116
117 my @errors = $this->schemaDoc->Validate($doc);
118 failed("The document isn't correct", @errors) if @errors;
119 my $name = ($doc->selectNodes("firstName"))[0]->nodeValue;
120 failed("The firstName has a wrong value", "Expected: Norman", "Got: $name") unless $name eq "Norman";
121
122 };
123
129 124
130 1; 125 1;