# HG changeset patch # User "uncorrelated zombie" # Date 1297924342 -32400 # Node ID 5e09f7cf87f55a3c05d2d53d3992963f9abf06d6 # Parent 861b93741d600952163c5b11ff33bcfcf53163dc Perl版のソースコードを追加。 diff -r 861b93741d60 -r 5e09f7cf87f5 Looping.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Looping.pl Thu Feb 17 15:32:22 2011 +0900 @@ -0,0 +1,21 @@ +#!/usr/bin/perl -w +use Time::HiRes qw(gettimeofday); +use Looping; + +sub gettimeofday_sec { + my ($sec, $microsec) = gettimeofday; + return $sec + $microsec*1e-6; +} + +my $o = Looping->new; +my $n = 1; + +my $t1 = gettimeofday_sec(); +for(my $c=0;$c<2147483647;$c++){ + $n = $o->calc($n); +} +my $t2 = gettimeofday_sec(); + +printf("%d\nPerl\t%f", $n, $t2 - $t1); + + diff -r 861b93741d60 -r 5e09f7cf87f5 Looping.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Looping.pm Thu Feb 17 15:32:22 2011 +0900 @@ -0,0 +1,19 @@ +package Looping; + +sub new { + my $class = shift; + my $self = { + n0 => 1 + }; + bless $self, $class; +} + +sub calc { + my $self = shift; + my $n = shift; + my $n1 = $self->{n0} + (1 - 2*($n%2)); + $self->{n0} = $n; + return $n1; +} + +1;