12
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
1 # クラス定義
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
2 setClass("Looping", contains = "numeric")
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
3 # 総称関数を宣言
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
4 setGeneric("calc", function(obj, n){
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
5 standardGeneric("calc")
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
6 })
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
7 # メソッドを追加
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
8 setMethod("calc", signature="Looping", definition=function(obj, n){
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
9 n1 <- obj@.Data + (1 - 2*(n%%2))
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
10 obj@.Data <- n1
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
11 return(n1)
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
12 })
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
13
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
14 # インスタンスを作成
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
15 l <- new("Looping")
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
16 c <- 0
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
17 n <- 1
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
18 t1 <- proc.time()
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
19 # 本当は2147483647でベンチマークすべき
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
20 repeat {
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
21 if(c>=2147483)
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
22 break
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
23 n <- calc(l, n)
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
24 c = c + 1
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
25 }
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
26 t2 <- proc.time()
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
27 print(paste(" R", t2["elapsed"] - t1["elapsed"]))
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
28 print(paste(" R", (t2["elapsed"] - t1["elapsed"])*2147483647/2147483, "[Estimate]"))
|