10
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
1 package main
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
2
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
3 import fmt "fmt"
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
4 import tm "time"
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
5
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
6 type Looping struct {
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
7 n0 int;
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
8 }
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
9
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
10 func (this *Looping) calc(n int) (int) {
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
11 var n1 = this.n0 + (1 - 2*(n%2))
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
12 this.n0 = n
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
13 return n1
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
14 }
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
15
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
16 func NewLooping () *Looping {
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
17 var o = new(Looping)
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
18 o.n0 = 0
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
19 return o
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
20 }
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
21
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
22 func main() {
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
23 var o = NewLooping()
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
24 var n = 1
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
25 var t1 = tm.Nanoseconds()
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
26 for c:=0; c<2147483647; c++ {
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
27 n = o.calc(n)
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
28 }
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
29 var t2 = tm.Nanoseconds()
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
30 fmt.Printf("%d\nGo:\t%f\n", n, ((float64)(t2 - t1))/1000000000)
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
31 }
|
"uncorrelated zombie" <uncorrelated@yahoo.co.jp>
parents:
diff
changeset
|
32
|