File: ref_bench.pl

package info (click to toggle)
libdata-util-perl 0.66-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 564 kB
  • ctags: 164
  • sloc: perl: 2,958; ansic: 416; makefile: 8
file content (44 lines) | stat: -rw-r--r-- 712 bytes parent folder | download | duplicates (5)
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
#!perl -w
use strict;
use warnings FATAL => 'all';

use Benchmark qw(:all);

use FindBin qw($Bin);
use lib $Bin;
use Common;

use Params::Util qw(_ARRAY0);
use Data::Util qw(:all);

signeture 'Data::Util' => \&is_array_ref, 'Params::Util' => \&_ARRAY0;

print "Benchmark: Params::Util::_ARRAY0() vs. Data::Util::is_array() vs. ref()\n";

foreach my $o([], {}, bless({}, 'Foo'), undef){
	print "\nFor ", neat($o), "\n";

	cmpthese -1 => {
		'_ARRAY0' => sub{
			for(1 .. 10){
				if(_ARRAY0($o)){
					;
				}
			}
		},
		'is_array_ref' => sub{
			for(1 .. 10){
				if(is_array_ref($o)){
					;
				}
			}
		},
		'ref() eq "ARRAY"' => sub{
			for(1 ..10){
				if(ref($o) eq 'ARRAY'){
					;
				}
			}
		},
	};
}