Last active
August 29, 2015 14:07
-
-
Save obscuren/067da8c4f13ae56ef3aa to your computer and use it in GitHub Desktop.
bench
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" | |
import "testing" | |
import "math/big" | |
/* | |
When ran it yields some surprising results | |
Set 50000000 37.6 ns/op | |
Assign 10000000 177 ns/op | |
Set64 50000000 30.2 ns/op | |
SetU64 100000000 31.9 ns/op | |
To my surprise a simple "assign" is the slowest of the | |
4 operations. I'd have thought that `Set` was the slowest | |
of the 3 `Set`s. And "Assign" would come out as a winner. | |
*/ | |
func main() { | |
base := new(big.Int) | |
a := testing.Benchmark(func(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
base.Set(new(big.Int)) | |
} | |
}) | |
fmt.Println("Set", a) | |
b := testing.Benchmark(func(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
base = new(big.Int) | |
} | |
}) | |
fmt.Println("Assign ", b) | |
c := testing.Benchmark(func(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
base.SetInt64(10) | |
} | |
}) | |
fmt.Println("Set64 ", c) | |
d := testing.Benchmark(func(b *testing.B) { | |
for i := 0; i < b.N; i++ { | |
base.SetUint64(10) | |
} | |
}) | |
fmt.Println("SetU64 ", d) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment