Created
November 1, 2016 05:25
-
-
Save kana-sama/3f52570e856942762ed668dec59b7879 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func now() int64 { | |
return time.Now().UnixNano() / int64(time.Millisecond) | |
} | |
func measure(task func()) int64 { | |
start := now() | |
task() | |
return now() - start | |
} | |
func printPI() { | |
var result float64 | |
isOdd := false | |
for i := float64(1); i < 10000000000; i += 2 { | |
delta := 1 / i | |
if isOdd { | |
result -= delta | |
} else { | |
result += delta | |
} | |
isOdd = !isOdd | |
} | |
fmt.Println(result * 4) | |
} | |
func main() { | |
fmt.Println(measure(printPI)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment