File: benchmark.pl

package info (click to toggle)
libxml-quote-perl 1.02-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 84 kB
  • sloc: perl: 259; makefile: 3
file content (82 lines) | stat: -rwxr-xr-x 1,243 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl
# $Version: release/perl/base/XML-Quote/t/benchmark.pl,v 1.4 2003/01/25 13:17:41 godegisel Exp $
use strict;
use XML::Quote;
use Benchmark;
use utf8;

use vars qw(@TESTS_0 @TESTS_1);

@TESTS_0=(
'plain text without any special symbols',
q{some symbols & "" ''''><<},
44,
123.11,
'некий "тест >в <\'ютф8 &',
);

timethese(1_000_000,{
'xs quote'	=>	sub {
	my $res;
	for my $t (@TESTS_0)	{
		$res=xml_quote($t);
	}
},

'perl quote'	=>	sub {
	my $res;
	for my $t (@TESTS_0)	{
		$res=perl_quote($t);
	}
},

});

@TESTS_1=(
'plain text without any special symbols',
q{some symbols &amp; &quot;&quot; &apos;&apos;&apos; &gt; &lt;&lt;},
44,
123.11,
'некий &quot;тест &gt;в &lt;&apos;ютф8 &amp;',
);

timethese(1_000_000,{
'xs dequote'	=>	sub {
	my $res;
	for my $t (@TESTS_1)	{
		$res=xml_dequote($t);
	}
},

'perl dequote'	=>	sub {
	my $res;
	for my $t (@TESTS_1)	{
		$res=perl_dequote($t);
	}
},

});

sub perl_quote	{
	my $str=shift;

	$str=~s/&/&amp;/g;
	$str=~s/"/&quot;/g;
	$str=~s/'/&apos;/g;
	$str=~s/>/&gt;/g;
	$str=~s/</&lt;/g;

	return $str;
}

sub perl_dequote	{
	my $str=shift;

	$str=~s/&quot;/"/g;
	$str=~s/&apos;/'/g;
	$str=~s/&gt;/>/g;
	$str=~s/&lt;/</g;
	$str=~s/&amp;/&/g;

	return $str;
}