# HG changeset patch # User "uncorrelated zombie" # Date 1298026706 -32400 # Node ID 30da8c1da4d4fb92e7209c4474811024feff145a # Parent d788c88f41bd72d3491be747967738163f4d7323# Parent 69b8c75e9c247ba3cb3b54e54ce3fd50ac206ed9 SmalltalkやScalar版のベンチマークを追加。 diff -r d788c88f41bd -r 30da8c1da4d4 Looping.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Looping.pl Fri Feb 18 19:58:26 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 d788c88f41bd -r 30da8c1da4d4 Looping.pm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Looping.pm Fri Feb 18 19:58:26 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; diff -r d788c88f41bd -r 30da8c1da4d4 Looping.rb diff -r d788c88f41bd -r 30da8c1da4d4 Looping.scala --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Looping.scala Fri Feb 18 19:58:26 2011 +0900 @@ -0,0 +1,21 @@ +class LClass { + def calc(n:Int): Int = { + var n1 = n0 + (1 - 2*(n%2)) + n0 = n; + return n1; + } + private var n0:Int = 0 +} + +object Looping { + def main(args :Array[String]):Unit = { + var o = new LClass() + var n = 1 + var t1 = System.currentTimeMillis() + for(c <- 0 to Integer.MAX_VALUE - 1){ + n = o.calc(n); + } + var t2 = System.currentTimeMillis() + println(n + "\nScala:\t" + (t2 - t1)) + } +} diff -r d788c88f41bd -r 30da8c1da4d4 Looping.st --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Looping.st Fri Feb 18 19:58:26 2011 +0900 @@ -0,0 +1,35 @@ +'From Squeak4.2 of 4 February 2011 [latest update: #10966] on 17 February 2011 at 8:44:09 am'! +Object subclass: #Looping + instanceVariableNames: 'n0' + classVariableNames: '' + poolDictionaries: '' + category: 'Benchmark-Looping'! + +!Looping methodsFor: 'calculation' stamp: 'sumim 2/17/2011 00:17'! +calc: n + | n1 | + n1 := n0 + (1 - (2 * (n \\ 2))). + n0 := n. + ^n1! ! + +!Looping methodsFor: 'initializing' stamp: 'sumim 2/16/2011 23:59'! +initialize + n0 := 0! ! + + +!Looping class methodsFor: 'benchmark' stamp: 'sumim 2/17/2011 00:52'! +benchmark + "self benchmark" + | l n t1 t2 | + l := Looping new. + n := 1. + t1 := Time millisecondClockValue. + 2147483647 timesRepeat: [ + n := l calc: n + ]. + t2 := Time millisecondClockValue. + Transcript cr; show: n printString. + Transcript cr; show: 'Smalltalk'; tab; show: (t2 - t1 / 1000.0) printString! ! + +Looping benchmark! +