なんか、CPAN探したら、clone系いっぱいあるんですね...。
- Clone
- Clone::Fast
- Scalar::Util::Clone
- Class::MakeMethods::Utility::Ref
いったいどれが速いんだってことで試してみた(Perl 5.8.4)。
Rate ref util dclone more fast normal ref 32.5/s -- -88% -89% -93% -93% -94% util 278/s 756% -- -4% -42% -43% -47% dclone 290/s 793% 4% -- -40% -41% -44% more 482/s 1384% 73% 66% -- -1% -7% fast 488/s 1402% 76% 68% 1% -- -6% normal 519/s 1500% 87% 79% 8% 6% --
なんだ、普通のかい...。
遅いのは除外して、バージョン変えてみて試してみた(Perl 5.8.7)。
Rate fast more normal fast 699/s -- -1% -10% more 704/s 1% -- -9% normal 775/s 11% 10% --
どっちにしても、普通のだった...。てか、Fast、Moreとほぼ一緒だな。
それよりも、Perlのバージョンあがると、スピード結構違いますねぇ。
追記:コードは下記です。
#!/usr/bin/perl use strict; use Benchmark; use Clone (); use Clone::Fast(); use Clone::More(); use Scalar::Util::Clone(); use Storable (); use Class::MakeMethods::Utility::Ref (); my $x = [map { [map { {0 => 1, abc => { hoge => [1,2,3]}}} 0..10] } 0 .. 10]; # my $x = [1,2,3]; Benchmark::cmpthese ( $ARGV[0] || 1000, { normal => sub { my $y = Clone::clone($x) }, fast => sub { my $y = Clone::Fast::clone($x) }, more => sub { my $y = Clone::More::clone($x) }, util => sub { my $y = Scalar::Util::Clone::clone($x) }, dclone => sub { my $y = Storable::dclone($x)}, ref => sub { my $y = Class::MakeMethods::Utility::Ref::ref_clone($x) }, } );