mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2025-02-19 23:23:14 +03:00
add missing package
This commit is contained in:
parent
e8bf182160
commit
284a608419
@ -1,25 +1,26 @@
|
|||||||
package profile
|
package profile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"log"
|
||||||
"log"
|
"math/big"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Duration(invocation time.Time, name string) {
|
func Duration(invocation time.Time, name string) {
|
||||||
elapsed := time.Since(invocation)
|
elapsed := time.Since(invocation)
|
||||||
|
|
||||||
log.Printf("%s lasted %s", name, elapsed)
|
log.Printf("%s lasted %s", name, elapsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BigIntFactorial(x big.Int) *big.Int {
|
func BigIntFactorial(x big.Int) *big.Int {
|
||||||
// Arguments to a defer statement is immediately evaluated and stored.
|
// Arguments to a defer statement is immediately evaluated and stored.
|
||||||
// The deferred function receives the pre-evaluated values when its invoked.
|
// The deferred function receives the pre-evaluated values when its invoked.
|
||||||
defer Duration(time.Now(), "IntFactorial")
|
defer Duration(time.Now(), "IntFactorial")
|
||||||
|
|
||||||
y := big.NewInt(1)
|
y := big.NewInt(1)
|
||||||
for one := big.NewInt(1); x.Sign() > 0; x.Sub(x, one) {
|
for one := big.NewInt(1); x.Sign() > 0; x.Sub(x, one) {
|
||||||
y.Mul(y, x)
|
y.Mul(y, x)
|
||||||
}
|
}
|
||||||
|
|
||||||
return x.Set(y)
|
return x.Set(y)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user