<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] ## 死碼消除概念 死碼消除(dead code elimination, DCE)是一種編譯器優化技術,用處是在編譯階段去掉對程序運行結果沒有任何影響的代碼 ## 應用 ### 使用常量提升性能 ``` // maxconst.go func max(num1, num2 int) int { if num1 > num2 { return num1 } return num2 } const a, b = 10, 20 func main() { if max(a, b) == a { fmt.Println(a) } } ``` 會被優化為 ``` func main() { if 20 == 10 { fmt.Println(a) } } ``` ### 可推斷的局部變量 ``` // maxvarlocal func main() { var a, b = 10, 20 if max(a, b) == a { fmt.Println(a) } } ``` 即 a、b 作為局部變量時,編譯器死碼消除是生效的 ### 調試(debug)模式 ``` const debug = false func main() { if debug { log.Println("debug mode is enabled") } } ``` 如果是正常編譯,常量 debug 始終等于 false,調試語句在編譯過程中會被消除,不會影響最終的二進制大小,也不會對運行效率產生任何影響 ### 條件編譯 debug.go ``` // +build debug package main const debug = true ``` release.go ``` // +build !debug package main const debug = false ``` 編譯debug ``` $ go build -tags debug -o debug . $ ./debug 2021/01/11 00:10:40 debug mode is enabled ``` 編譯 release ``` $ go build -o release . $ ./release # no output ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看