Mercurial > op > Looping
view Looping.go @ 10:308cc64c24b9 >>178
Goのソースコードを追加。
author | "uncorrelated zombie" <uncorrelated@yahoo.co.jp> |
---|---|
date | Thu, 24 Feb 2011 07:31:17 +0900 |
parents | |
children |
line wrap: on
line source
package main import fmt "fmt" import tm "time" type Looping struct { n0 int; } func (this *Looping) calc(n int) (int) { var n1 = this.n0 + (1 - 2*(n%2)) this.n0 = n return n1 } func NewLooping () *Looping { var o = new(Looping) o.n0 = 0 return o } func main() { var o = NewLooping() var n = 1 var t1 = tm.Nanoseconds() for c:=0; c<2147483647; c++ { n = o.calc(n) } var t2 = tm.Nanoseconds() fmt.Printf("%d\nGo:\t%f\n", n, ((float64)(t2 - t1))/1000000000) }