~ubuntu-branches/ubuntu/wily/libxml-bare-perl/wily

« back to all changes in this revision

Viewing changes to bench/onetree.pl

  • Committer: Package Import Robot
  • Author(s): Nuno Carvalho, gregor herrmann, Salvatore Bonaccorso, Axel Beckert, Nuno Carvalho
  • Date: 2013-09-17 15:54:28 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130917155428-4d0xb5cissw2323f
Tags: 0.53-1
* Team upload.

[ gregor herrmann ]
* debian/control: update {versioned,alternative} (build) dependencies.

[ Salvatore Bonaccorso ]
* Change Vcs-Git to canonical URI (git://anonscm.debian.org)
* Change search.cpan.org based URIs to metacpan.org based URIs

[ Axel Beckert ]
* debian/copyright: migrate pre-1.0 format to 1.0 using "cme fix dpkg-
  copyright"

[ Nuno Carvalho ]
* New upstream release.
* debian/copyright: update copyright years.
* debian/control: update standards version.
* debian/control: update debhelper required version, in order to pass all
  the hardening flags to EUMM.
* Add lintian override to apparently false-positive warning.
* Add set of patches accepted upstream but still not included in this
  release, visit https://rt.cpan.org/Public/Bug/Display.html?id=88155
  for details.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl
2
 
use strict;
3
 
 
4
 
my $div    = "\/";
5
 
my $maxlen = 26;
6
 
my $file   = $ARGV[1] || 'test.xml';
7
 
my ( $root, $s, $s2, $s3, $usec, $usec2, $usec3, $sa, $sb, $sc, $base1, $base2, $base3 );
8
 
 
9
 
my $onlyone = $ARGV[2] ? 1 : 0;
10
 
 
11
 
tabit( "-Module-", 'load    ', 'parse   ', 'total' ) if ( !$onlyone );
12
 
 
13
 
exit if ( !$ARGV[0] );
14
 
 
15
 
use Time::HiRes qw(gettimeofday);
16
 
 
17
 
# For fairness; try to get the file to be read into memory cache
18
 
{
19
 
    open( FILE, '<', $file ) or die "Couldn't open $!";
20
 
    local $/ = undef;
21
 
    my $cache = <FILE>;
22
 
    close(FILE);
23
 
}
24
 
 
25
 
if ( $ARGV[0] * 1 >= 0 ) {
26
 
    ( $s, $usec ) = gettimeofday();
27
 
    if ( eval('require XML::Bare;') ) {
28
 
        ( $s2, $usec2 ) = gettimeofday();
29
 
 
30
 
        my $ob = new XML::Bare( file => $file );
31
 
        $root = $ob->parse();
32
 
 
33
 
        ( $s3, $usec3 ) = gettimeofday();
34
 
        unload('XML::Bare');
35
 
        timeit( 'XML::Bare', 1 );
36
 
    }
37
 
}
38
 
 
39
 
if ( $ARGV[0] eq '1' ) {
40
 
    ( $s, $usec ) = gettimeofday();
41
 
    if ( eval('require XML::Bare;') ) {
42
 
        ( $s2, $usec2 ) = gettimeofday();
43
 
 
44
 
        my $ob = new XML::Bare( file => $file );
45
 
        my $root = $ob->simple();
46
 
 
47
 
        ( $s3, $usec3 ) = gettimeofday();
48
 
        unload('XML::Bare (simple)');
49
 
        timeit('XML::Bare (simple)');
50
 
    }
51
 
}
52
 
 
53
 
if ( $ARGV[0] eq '2' ) {
54
 
    ( $s, $usec ) = gettimeofday();
55
 
    if ( eval('require XML::TreePP;') ) {
56
 
        ( $s2, $usec2 ) = gettimeofday();
57
 
 
58
 
        my $tpp  = XML::TreePP->new();
59
 
        my $tree = $tpp->parsefile($file);
60
 
 
61
 
        ( $s3, $usec3 ) = gettimeofday();
62
 
        unload('XML::TreePP');
63
 
        timeit('XML::TreePP');
64
 
    }
65
 
}
66
 
 
67
 
if ( $ARGV[0] eq '3' ) {
68
 
    ( $s, $usec ) = gettimeofday();
69
 
    if ( eval('require XML::Parser; require XML::Parser::EasyTree;') ) {
70
 
        ( $s2, $usec2 ) = gettimeofday();
71
 
 
72
 
        my $p1 = new XML::Parser( Style => 'EasyTree' );
73
 
        $root = $p1->parsefile($file);
74
 
 
75
 
        ( $s3, $usec3 ) = gettimeofday();
76
 
        unload('XML::Parser::EasyTree');
77
 
        timeit('XML::Parser::EasyTree');
78
 
    }
79
 
}
80
 
 
81
 
if ( $ARGV[0] eq '4' ) {
82
 
    ( $s, $usec ) = gettimeofday();
83
 
    if ( eval('require XML::Handler::Trees; require XML::Parser::PerlSAX;') ) {
84
 
        ( $s2, $usec2 ) = gettimeofday();
85
 
 
86
 
        my $p = XML::Parser::PerlSAX->new();
87
 
        my $h = XML::Handler::EasyTree->new();
88
 
        $root = $p->parse( Handler => $h, Source => { SystemId => $file } );
89
 
 
90
 
        ( $s3, $usec3 ) = gettimeofday();
91
 
        unload('XML::Handler::Trees');
92
 
        timeit('XML::Handler::Trees');
93
 
    }
94
 
}
95
 
 
96
 
if ( $ARGV[0] eq '5' ) {
97
 
    ( $s, $usec ) = gettimeofday();
98
 
    if ( eval('require XML::Trivial;') ) {
99
 
        ( $s2, $usec2 ) = gettimeofday();
100
 
 
101
 
        my $xml = XML::Trivial::parseFile($file);
102
 
 
103
 
        ( $s3, $usec3 ) = gettimeofday();
104
 
        unload('XML::Trivial');
105
 
        timeit('XML::Trivial');
106
 
    }
107
 
}
108
 
 
109
 
if ( $ARGV[0] eq '6' ) {
110
 
    ( $s, $usec ) = gettimeofday();
111
 
    if ( eval('require XML::Smart;') ) {
112
 
        ( $s2, $usec2 ) = gettimeofday();
113
 
 
114
 
        my $XML = XML::Smart->new($file);
115
 
 
116
 
        ( $s3, $usec3 ) = gettimeofday();
117
 
        unload('XML::Smart');
118
 
        timeit('XML::Smart');
119
 
    }
120
 
}
121
 
 
122
 
if ( $ARGV[0] eq '7' ) {
123
 
    ( $s, $usec ) = gettimeofday();
124
 
    if ( eval('require XML::Simple;') ) {
125
 
        ( $s2, $usec2 ) = gettimeofday();
126
 
 
127
 
        $XML::Simple::PREFERRED_PARSER = 'XML::Parser';
128
 
        my $ref = XML::Simple::XMLin($file);
129
 
 
130
 
        ( $s3, $usec3 ) = gettimeofday();
131
 
        unload('XML::Simple (XML::Parser)');
132
 
        timeit('XML::Simple (XML::Parser)');
133
 
    }
134
 
}
135
 
 
136
 
if ( $ARGV[0] eq '8' ) {
137
 
    ( $s, $usec ) = gettimeofday();
138
 
    if ( eval('require XML::Simple;') ) {
139
 
        ( $s2, $usec2 ) = gettimeofday();
140
 
 
141
 
        $XML::Simple::PREFERRED_PARSER = 'XML::SAX::PurePerl';
142
 
        my $ref = XML::Simple::XMLin($file);
143
 
 
144
 
        ( $s3, $usec3 ) = gettimeofday();
145
 
        unload('XML::Simple (PurePerl)');
146
 
        timeit('XML::Simple (PurePerl)');
147
 
    }
148
 
}
149
 
 
150
 
if ( $ARGV[0] eq '9' ) {
151
 
    ( $s, $usec ) = gettimeofday();
152
 
    if ( eval('require XML::Simple;') ) {
153
 
        ( $s2, $usec2 ) = gettimeofday();
154
 
 
155
 
        $XML::Simple::PREFERRED_PARSER = 'XML::LibXML::SAX::Parser';
156
 
        my $ref = XML::Simple::XMLin($file);
157
 
 
158
 
        ( $s3, $usec3 ) = gettimeofday();
159
 
        unload('XML::Simple (LibXML)');
160
 
        timeit('XML::Simple (LibXML)');
161
 
    }
162
 
}
163
 
 
164
 
if ( $ARGV[0] eq '10' ) {
165
 
    ( $s, $usec ) = gettimeofday();
166
 
    if ( eval('require XML::Simple;') ) {
167
 
        ( $s2, $usec2 ) = gettimeofday();
168
 
 
169
 
        $XML::Simple::PREFERRED_PARSER = 'XML::Bare::SAX::Parser';
170
 
        my $ref = XML::Simple::XMLin($file);
171
 
 
172
 
        ( $s3, $usec3 ) = gettimeofday();
173
 
        unload('XML::Simple (XML Bare)');
174
 
        timeit('XML::Simple (XML Bare)');
175
 
    }
176
 
}
177
 
 
178
 
if ( $ARGV[0] eq '11' ) {
179
 
    ( $s, $usec ) = gettimeofday();
180
 
    if ( eval('require XML::Bare::Simple;') ) {
181
 
        ( $s2, $usec2 ) = gettimeofday();
182
 
 
183
 
        my $ref = XML::Bare::Simple::XMLin($file);
184
 
 
185
 
        ( $s3, $usec3 ) = gettimeofday();
186
 
        unload('XML::Bare::Simple');
187
 
        timeit('XML::Bare::Simple');
188
 
    }
189
 
}
190
 
 
191
 
if ( $ARGV[0] eq '12' ) {
192
 
    ( $s, $usec ) = gettimeofday();
193
 
    if ( eval('require XML::SAX::Simple;') ) {
194
 
        ( $s2, $usec2 ) = gettimeofday();
195
 
 
196
 
        my $ref = XML::SAX::Simple::XMLin($file);
197
 
 
198
 
        ( $s3, $usec3 ) = gettimeofday();
199
 
        unload('XML::SAX::Simple');
200
 
        timeit('XML::SAX::Simple');
201
 
    }
202
 
}
203
 
 
204
 
if ( $ARGV[0] eq '13' ) {
205
 
    ( $s, $usec ) = gettimeofday();
206
 
    if ( eval('require XML::Twig;') ) {
207
 
        ( $s2, $usec2 ) = gettimeofday();
208
 
 
209
 
        my $t = XML::Twig->new->parsefile($file);
210
 
        $root = $t->root->simplify;
211
 
 
212
 
        ( $s3, $usec3 ) = gettimeofday();
213
 
        unload('XML::Twig');
214
 
        timeit('XML::Twig');
215
 
    }
216
 
}
217
 
 
218
 
if ( $ARGV[0] eq '14' ) {
219
 
    ( $s, $usec ) = gettimeofday();
220
 
    if ( eval('require XML::Grove::Builder; require XML::Parser::PerlSAX;') ) {
221
 
        ( $s2, $usec2 ) = gettimeofday();
222
 
 
223
 
        my $grove_builder = XML::Grove::Builder->new;
224
 
        my $parser        = XML::Parser::PerlSAX->new( Handler => $grove_builder );
225
 
        my $document      = $parser->parse( Source => { SystemId => $file } );
226
 
 
227
 
        ( $s3, $usec3 ) = gettimeofday();
228
 
        unload('XML::Grove::Builder');
229
 
        timeit('XML::Grove::Builder');
230
 
    }
231
 
}
232
 
 
233
 
if ( $ARGV[0] eq '15' ) {
234
 
    ( $s, $usec ) = gettimeofday();
235
 
    if ( eval('require XML::XPath::XMLParser;') ) {
236
 
        ( $s2, $usec2 ) = gettimeofday();
237
 
 
238
 
        my $parser = XML::XPath::XMLParser->new;
239
 
        my $tree   = $parser->parsefile($file);
240
 
 
241
 
        ( $s3, $usec3 ) = gettimeofday();
242
 
        unload('XML::XPath::XMLParser');
243
 
        timeit('XML::XPath::XMLParser');
244
 
    }
245
 
}
246
 
 
247
 
if ( $ARGV[0] eq '16' ) {
248
 
    ( $s, $usec ) = gettimeofday();
249
 
    if ( eval('require XML::DOM::Lite;') ) {
250
 
        ( $s2, $usec2 ) = gettimeofday();
251
 
 
252
 
        my $doc = XML::DOM::Lite::Parser->parseFile($file);
253
 
 
254
 
        ( $s3, $usec3 ) = gettimeofday();
255
 
        unload('XML::DOM::Lite');
256
 
        timeit('XML::DOM::Lite');
257
 
    }
258
 
}
259
 
 
260
 
if ( $ARGV[0] eq '17' ) {
261
 
    ( $s, $usec ) = gettimeofday();
262
 
    if ( eval('require XML::Tiny;') ) {
263
 
        ( $s2, $usec2 ) = gettimeofday();
264
 
 
265
 
        my $xmlfile;
266
 
        open( $xmlfile, $file );
267
 
        my $doc = XML::Tiny::parsefile($xmlfile);
268
 
 
269
 
        ( $s3, $usec3 ) = gettimeofday();
270
 
        unload('XML::Tiny');
271
 
        timeit('XML::Tiny');
272
 
    }
273
 
}
274
 
 
275
 
if ( $ARGV[0] eq '18' ) {
276
 
    ( $s, $usec ) = gettimeofday();
277
 
    if ( eval('require XML::MyXML;') ) {
278
 
        ( $s2, $usec2 ) = gettimeofday();
279
 
 
280
 
        my $ob = XML::MyXML::xml_to_object( $file, { file => 1 } );
281
 
 
282
 
        ( $s3, $usec3 ) = gettimeofday();
283
 
        unload('XML::MyXML');
284
 
        timeit('XML::MyXML');
285
 
    }
286
 
}
287
 
 
288
 
if ( $ARGV[0] eq '19' ) {
289
 
    ( $s, $usec ) = gettimeofday();
290
 
    if ( eval('require XML::TinyXML;') ) {
291
 
        ( $s2, $usec2 ) = gettimeofday();
292
 
 
293
 
        my $ob = XML::TinyXML->new();
294
 
        $ob->loadFile($file);
295
 
 
296
 
        ( $s3, $usec3 ) = gettimeofday();
297
 
        unload('XML::TinyXML');
298
 
        timeit('XML::TinyXML');
299
 
    }
300
 
}
301
 
 
302
 
sub unload {
303
 
    my $module = shift;
304
 
    my @parts = split( ' ', $module );
305
 
    $module = $parts[0];
306
 
    $module =~ s/::/\//g;
307
 
    $module .= '.pm';
308
 
    delete $INC{$module};
309
 
}
310
 
 
311
 
sub timeit {
312
 
    my $name = shift;
313
 
    my $base = shift;
314
 
    $sa = $s2 - $s +  ( ( $usec2 - $usec ) / 1000000 );
315
 
    $sb = $s3 - $s2 + ( ( $usec3 - $usec2 ) / 1000000 );
316
 
    $sc = $s3 - $s +  ( ( $usec3 - $usec ) / 1000000 );
317
 
    if ($base) {
318
 
        $base1 = $sa;
319
 
        $base2 = $sb;
320
 
        $base3 = $sc;
321
 
    }
322
 
    $sa /= $base1;
323
 
    $sb /= $base2;
324
 
    $sc /= $base3;
325
 
    $sa = fixed($sa);
326
 
    $sb = fixed($sb);
327
 
    $sc = fixed($sc);
328
 
    if ( !$base || !$onlyone ) {
329
 
        tabit( $name, $sa, $sb, $sc );
330
 
    }
331
 
}
332
 
 
333
 
sub tabit {
334
 
    my ( $a, $b, $c, $d ) = @_;
335
 
    my $len = length($a);
336
 
    print $a;
337
 
    for ( 0 .. ( $maxlen - $len ) ) { print ' '; }
338
 
    print "$b $c $d
339
 
";
340
 
}
341
 
 
342
 
sub fixed {
343
 
    my $in = shift;
344
 
    $in *= 10000;
345
 
    $in = int($in);
346
 
    $in /= 10000;
347
 
    my $a   = "$in";
348
 
    my $len = length($a);
349
 
    if ( $len > 8 ) { $a = substr( $a, 8 ); }
350
 
    if ( $len < 8 ) {
351
 
        while ( $len < 8 ) {
352
 
            $a   = "${a} ";
353
 
            $len = length($a);
354
 
        }
355
 
    }
356
 
    return $a;
357
 
}