Setting GODEBUG=inittrace=1 will log a trace of init function execution,
which you can use to determine if init is slow, and if so which packages.

e.g., `GODEBUG=inittrace=1 go version` ends with "init main @9.5 ms",
indicating that it look 9.5ms to run all init functions.

The format is described at
https://pkg.go.dev/runtime#hdr-Environment_Variables.

On Wed, Aug 31, 2022 at 3:00 AM ag9920 <jingong.w...@gmail.com> wrote:

> Hi, recently I've been trying to make my unit test faster. It seems too
> much time were spent on initialization. After removing all init() function
> in relevant packages. The speed was still very slow.It even takes dozens of
> seconds before entering my real unit test function.
>
> So I take a look at all the possible factors that might slow down the
> testing. The only possible reason I can think of is the time cost on
> import. Golang needs to import all packages recursively. And in my
> scenario, that's roughly dozens of packages.Maybe initializing const, var
> takes too much time.
>
> Is there any solution that could help me figured out the reason? I didn't
> find any tools that could tell me the time cost on import several packages.
>
> And if that's the case,  import a package does take much time, is it still
> possible for me to speed up my unit test?
>
>
> --
> 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/cd58955e-0c4b-4d56-afd7-1153d7be06dcn%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/cd58955e-0c4b-4d56-afd7-1153d7be06dcn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CALoThU9aog7qArW8%3DfHQ6QL5gA%3DAV1136Mib0d3EOeJsfXv3oQ%40mail.gmail.com.

Reply via email to