繁体   English   中英

在应用程序启动时读取 Bundle.main.path 是否耗时?

[英]Reading Bundle.main.path at the launching of the app is time consuming or not?

对于特定于应用程序,我有与环境和配置相关的 json 文件,在启动应用程序时读取这些文件是否耗时? (当然我在启动时需要它)如果是的话,我将使用脚本创建结构常量

Bundle.main.path(forResource: ConfigPath.urlString(api: .environment), ofType: "json")

读取或写入文件是最耗费资源的操作之一。 无论您是否在应用程序启动时执行此操作。 如果您想检查它如何影响启动时间,您可以创建一个简单的 UI 测试并在有和没有文件操作的情况下运行它。

import XCTest

class UILaunchTests: XCTestCase {
  func testLaunchPerformance() {
    if #available(macOS 10.15, iOS 13.0, tvOS 13.0, *) {
      measure(metrics: [XCTOSSignpostMetric.applicationLaunch]) {
        XCUIApplication().launch()
      }
    }
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM