如何在 Xcode 中打开优化?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34497831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:22:02  来源:igfitidea点击:

How do I turn on optimization in Xcode?

xcodeswiftoptimizationbuild

提问by Brian Kendig

I have some Swift code in Xcode 7.2 that runs well, but when I run swift -O main.swiftfrom a command line to run an optimized build of it, my code runs really fast.

我在 Xcode 7.2 中有一些运行良好的 Swift 代码,但是当我从命令行运行swift -O main.swift以运行它的优化构建时,我的代码运行得非常快。

How do I turn on code optimization in Xcode? I've tried Product -> Build For -> Running, but that isn't running it at optimized speed. I don't see anything in the project settings for "enable optimization" or "make a release build".

如何在 Xcode 中打开代码优化?我已经尝试过 Product -> Build For -> Running,但这并没有以优化的速度运行它。我在“启用优化”或“发布版本”的项目设置中没有看到任何内容。

回答by

If you select Product -> Scheme -> Edit Scheme, then target the Run scheme, you'll see that it has two build configurations:

如果选择Product -> Scheme -> Edit Scheme,然后定位 Run 方案,您将看到它有两个构建配置:

  • Debug: Builds with option -O0for no optimization.
  • Release: Builds with option -Osfor fastest/smallest optimization.
  • 调试:使用-O0无优化选项构建。
  • 发布:使用-Os最快/最小优化选项构建。

You can find those values in the project's Build Settings, under Apple LLVM 7.0 - Code Generation, Optimization Level.

您可以在Apple LLVM 7.0 - Code Generation, Optimization Level下的项目构建设置中找到这些值。

One option is to edit the Run scheme's build configuration, which defaults to Debug, and change it to Release.

一种选择是编辑运行方案的构建配置,默认为调试,并将其更改为发布。

Another option is to build for profiling which defaults to Release, and will build an optimized version that can be profiled.

另一种选择是构建默认为 Release 的分析,并将构建一个可以进行分析的优化版本。