comparison Looping.go @ 10:308cc64c24b9 >>178

Goのソースコードを追加。
author "uncorrelated zombie" <uncorrelated@yahoo.co.jp>
date Thu, 24 Feb 2011 07:31:17 +0900
parents
children
comparison
equal deleted inserted replaced
9:30b521e712f5 10:308cc64c24b9
1 package main
2
3 import fmt "fmt"
4 import tm "time"
5
6 type Looping struct {
7 n0 int;
8 }
9
10 func (this *Looping) calc(n int) (int) {
11 var n1 = this.n0 + (1 - 2*(n%2))
12 this.n0 = n
13 return n1
14 }
15
16 func NewLooping () *Looping {
17 var o = new(Looping)
18 o.n0 = 0
19 return o
20 }
21
22 func main() {
23 var o = NewLooping()
24 var n = 1
25 var t1 = tm.Nanoseconds()
26 for c:=0; c<2147483647; c++ {
27 n = o.calc(n)
28 }
29 var t2 = tm.Nanoseconds()
30 fmt.Printf("%d\nGo:\t%f\n", n, ((float64)(t2 - t1))/1000000000)
31 }
32