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