On Thu, Oct 24, 2019 at 2:11 AM 陈清和 <chenqh...@gmail.com> wrote: > > here is the code: > > ```go > func main() { > for i := 0; i < 10; i++ { > start := time.Now() > time.Now().Format("20060102150405") > end := time.Now() > fmt.Println(end.Sub(start)) > } > } > > // output: > > 34.9788ms > 0s > 0s > 0s > 0s > 0s > 0s > 0s > 0s > 0s > ``` > > here are my questions: > 1. why Format so slow? > 2. why Format() become fast after first called? > > could someone help me? thanks a lot.
It's because time.Now is assumed to be in the local time zone, so formatting it requires fetching the local time zone information to decide how much to offset the time from UTC when printing it. The local time zone information is cached, so the program only pays that price the first time you format a local time. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcW7DUpmGujDse3%3D1mO1oJ48G%2BNipVjF%2B41n%3DuhREVydBw%40mail.gmail.com.