comparison _test/any.pl @ 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
1 #!/usr/bin/perl -w 1 #!/usr/bin/perl -w
2 use strict; 2 use strict;
3 use lib '..\Lib'; 3 use lib '..\Lib';
4 4
5 require IMPL::DOM::Navigator::SimpleBuilder; 5 require IMPL::DOM::Navigator::SimpleBuilder;
6 require IMPL::DOM::XMLReader;
6 7
7 my $builder = IMPL::DOM::Navigator::SimpleBuilder->new(); 8 my $builder = IMPL::DOM::Navigator::SimpleBuilder->new();
8 9
9 use Time::HiRes qw(gettimeofday tv_interval); 10 use Time::HiRes qw(gettimeofday tv_interval);
10 11
15 $builder->Back(); 16 $builder->Back();
16 $builder->NavigateCreate('lastName')->nodeValue('Nobel'); 17 $builder->NavigateCreate('lastName')->nodeValue('Nobel');
17 $builder->Back(); 18 $builder->Back();
18 $builder->NavigateCreate('lastName')->nodeValue('Gardum'); 19 $builder->NavigateCreate('lastName')->nodeValue('Gardum');
19 $builder->Back(); 20 $builder->Back();
20 for(1..10000) { 21 for(my $i = 0 ; $i < 10000; $i++) {
21 $builder->NavigateCreate('address', local => 1); 22 $builder->NavigateCreate('address', local => 1);
22 $builder->NavigateCreate('street')->nodeValue('Hellroad'); 23 $builder->NavigateCreate('street')->nodeValue('Hellroad');
23 $builder->Back(); 24 $builder->Back();
24 $builder->NavigateCreate('line')->nodeValue($_); 25 $builder->NavigateCreate('line')->nodeValue($_);
25 $builder->Back(); 26 $builder->Back();
26 $builder->Back(); 27 $builder->Back();
27 } 28 }
28 $builder->Back(); 29 $builder->Back();
29 30
30 print "Build: ",tv_interval($t,[gettimeofday]),"\n"; 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 }