changeset 8:30da8c1da4d4 >>178

SmalltalkやScalar版のベンチマークを追加。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Fri, 18 Feb 2011 19:58:26 +0900
parents d788c88f41bd (current diff) 69b8c75e9c24 (diff)
children 30b521e712f5
files Looping.rb
diffstat 4 files changed, 96 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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);
+
+
--- /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;
--- /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))
+	}
+}
--- /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!
+