hashの全ての要素に何かするベンチマーク その2

 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
Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
Platform:
osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread
uname=''
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc', ccflags =' -s -O2 -DWIN32 -DHAVE_DES_FCRYPT  -DPERL_IMPLICIT_CONTE
XT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -DPERL_MSVCRT_READFIX',
optimize='-s -O2',
cppflags='-DWIN32'
ccversion='', gccversion='3.4.5', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long long', lseek
size=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='g++', ldflags ='-s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\li
b"'
libpth=C:\strawberry\c\lib
libs= -lmsvcrt -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32
-ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm
-lversion -lodbc32 -lodbccp32
perllibs= -lmsvcrt -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdl
g32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lw
inmm -lversion -lodbc32 -lodbccp32
libc=-lmsvcrt, so=dll, useshrplib=true, libperl=libperl510.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-mdll -s -L"C:\strawberry\perl\lib\CORE" -L"C:\st
rawberry\c\lib"'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
PERL_IMPLICIT_CONTEXT PERL_IMPLICIT_SYS
PERL_MALLOC_WRAP PL_OP_SLAB_ALLOC USE_ITHREADS
USE_LARGE_FILES USE_PERLIO
Built under MSWin32
Compiled at Oct 19 2008 15:47:04
@INC:
C:/strawberry/perl/lib
C:/strawberry/perl/site/lib
.
1
2
3
4
              Rate    sub_each sub_foreach     sub_for
sub_each    28.4/s          --         -9%        -10%
sub_foreach 31.2/s         10%          --         -2%
sub_for     31.6/s         11%          2%          --
 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
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw(:all);
use Digest::MD5 ();
# use Data::Dumper;
my %hash;
for my $i (1 .. 10000) {
my $digest = Digest::MD5::md5($i);
$hash{ $digest } = $i;
}
cmpthese( 100, {
sub_for => sub {
my @array;
for my $key (keys %hash) {
push @array, { -key => $key, -val => $hash{$key} };
}
#        print Dumper(\@array);
},
sub_foreach => sub {
my @array;
foreach my $key (keys %hash) {
push @array, { -key => $key, -val => $hash{$key} };
}
#        print Dumper(\@array);
},
sub_each => sub {
my @array;
while ( my ($key, $value) =  each %hash) {
push @array, { -key => $key, -val => $value };
}
#        print Dumper(\@array);
},
});
1
2
3
4
              Rate    sub_each sub_foreach     sub_for
sub_each    2.68/s          --        -11%        -14%
sub_foreach 3.00/s         12%          --         -3%
sub_for     3.11/s         16%          3%          --
1
2
3
4
               Rate    sub_each     sub_for sub_foreach
sub_each    21692/s          --        -19%        -20%
sub_for     26896/s         24%          --         -1%
sub_foreach 27233/s         26%          1%          --
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy