# HG changeset patch # User "uncorrelated zombie" # Date 1328296201 -32400 # Node ID dab1e83799e4e321550b9f3afc7b09e6f2173f93 # Parent b952a5d72c9f70e0e9619319cab5247c5bc40a7f R版のソースコードを追加。 diff -r b952a5d72c9f -r dab1e83799e4 Looping.R --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Looping.R Sat Feb 04 04:10:01 2012 +0900 @@ -0,0 +1,28 @@ +# クラス定義 +setClass("Looping", contains = "numeric") +# 総称関数を宣言 +setGeneric("calc", function(obj, n){ + standardGeneric("calc") +}) +# メソッドを追加 +setMethod("calc", signature="Looping", definition=function(obj, n){ + n1 <- obj@.Data + (1 - 2*(n%%2)) + obj@.Data <- n1 + return(n1) +}) + +# インスタンスを作成 +l <- new("Looping") +c <- 0 +n <- 1 +t1 <- proc.time() +# 本当は2147483647でベンチマークすべき +repeat { + if(c>=2147483) + break + n <- calc(l, n) + c = c + 1 +} +t2 <- proc.time() +print(paste(" R", t2["elapsed"] - t1["elapsed"])) +print(paste(" R", (t2["elapsed"] - t1["elapsed"])*2147483647/2147483, "[Estimate]"))