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