Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Latest commit

 

History

History
 
 

SwiftModelsBenchmarksCore

Adding new settings

Let's walk through the process of adding a new String-typed setting:

  1. Add a new setting to BenchmarkSettings.swift:

    a. Add a new setting type:

    public struct MySetting: BenchmarkSetting {
      var value: String
      init(_ value: String) {
        self.value = value
      }
    }

    b. Add a default (if appropriate) to the defaultSettings in the same file:

    public let defaultSettings: [BenchmarkSetting] = [
      ...
      MySetting("...") // default value goes here
      ...
    ]

    c. Add a convenience getter to the BenchmarkSettings extension:

      var mySetting: String? {
        return self[MySetting.self]?.value
      }

    If your setting has a default you can unwrap the optional and return non-optional result:

      var mySetting: String {
        if let value = self[MySetting.self]?.value {
          return value
        } else {
          fatalError("MySetting setting must have a default.")
        }
      }
  2. Add a new benchmark flag to BenchmarkArguments.swift:

    a. Add a flag property:

    @Option(help: "Useful description of MySetting here.")
    var mySettingFlagName: String?

    b. Validate your flag value in BenchmarkArguments.validate() function if necessary.

    c. Convert command-line flag to a setting in BenchmarkArgument.settings computed property:

      if let value = mySettingFlagName {
        settings.append(MySetting(value))
      }