annotate _test/any.pl @ 41:c442eb67fa22

parser in progress
author Sergey
date Mon, 21 Dec 2009 17:40:09 +0300
parents c2e7f7c96bcd
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
1 #!/usr/bin/perl -w
18
818c74b038ae DOM Schema + tests
Sergey
parents: 11
diff changeset
2 use strict;
36
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
3 use lib '..\Lib';
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
4
36
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
5 require IMPL::DOM::Navigator::SimpleBuilder;
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
6 require IMPL::DOM::XMLReader;
11
75980091813b DOM и навигация
Sergey
parents:
diff changeset
7
36
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
8 my $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
9
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
10 use Time::HiRes qw(gettimeofday tv_interval);
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
11
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
12 my $t = [gettimeofday];
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
13
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
14 $builder->NavigateCreate('personInfo', version => '1');
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
15 $builder->NavigateCreate('firstName')->nodeValue('Nemo');
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
16 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
17 $builder->NavigateCreate('lastName')->nodeValue('Nobel');
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
18 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
19 $builder->NavigateCreate('lastName')->nodeValue('Gardum');
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
20 $builder->Back();
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
21 for(my $i = 0 ; $i < 10000; $i++) {
36
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
22 $builder->NavigateCreate('address', local => 1);
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
23 $builder->NavigateCreate('street')->nodeValue('Hellroad');
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
24 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
25 $builder->NavigateCreate('line')->nodeValue($_);
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
26 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
27 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
28 }
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
29 $builder->Back();
1828103371d0 DOM in works
Sergey
parents: 18
diff changeset
30
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
31 print "Build: ",tv_interval($t,[gettimeofday]),"\n";
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
32
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
33 $t = [gettimeofday];
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
34
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
35 my $doc = new IMPL::DOM::Document(nodeName => 'doc');
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
36 for(my $i = 0 ; $i < 30000; $i++) {
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
37 my $node = new IMPL::DOM::Node(nodeName => 'test');
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
38 $node->nodeValue(100);
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
39 $doc->appendChild($node);
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
40 }
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
41
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
42 print "Create 30000 nodes: ",tv_interval($t,[gettimeofday]),"\n";
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
43
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
44 $t = [gettimeofday];
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
45 $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
46 my $reader = IMPL::DOM::XMLReader->new( Navigator => $builder );
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
47
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
48 $reader->ParseFile("Resources/large.xml");
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
49 print "Parsing large Xml file: ",tv_interval($t,[gettimeofday]),"\n";
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
50
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
51 my $count = selectAll($builder->Document);
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
52 my $len = length $builder->Document->text;
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
53 print "Total nodes loaded: $count, data length: $len\n";
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
54
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
55 $t = [gettimeofday];
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
56 $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
57 my $reader2 = IMPL::DOM::XMLReader->new( Navigator => $builder );
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
58
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
59 $reader2->ParseFile("Resources/person_info.xml");
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
60 print "Parsing small Xml file: ",tv_interval($t,[gettimeofday]),"\n";
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
61
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
62 sub selectAll {
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
63 my $node = shift;
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
64 $node,map selectAll($_),@{$node->childNodes};
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
65 }