<commit_before>/*
 This source file is part of the Swift.org open source project

 Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
 Licensed under Apache License v2.0 with Runtime Library Exception

 See http://swift.org/LICENSE.txt for license information
 See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import XCTest

import Basic
import TestSupport
import PackageLoading

class ManifestLoadingPerfTests: XCTestCasePerf {
    let manifestLoader = ManifestLoader(manifestResources: Resources.default)

    func write(_ bytes: ByteString, body: (AbsolutePath) -> ()) {
        mktmpdir { path in
            let manifestFile = path.appending(component: "Package.swift")
            try localFileSystem.writeFileContents(manifestFile, bytes: bytes)
            body(path)
        }
    }

    func testTrivialManifestLoading_X1() {
        let N = 1
        let trivialManifest = ByteString(encodingAsUTF8: ("""
            import PackageDescription
            let package = Package(name: "Trivial")
            """))
        write(trivialManifest) { path in
            measure {
                for _ in 0..<N {
                    let manifest = try! self.manifestLoader.load(package: path, baseURL: "/", manifestVersion: .v4)
                    XCTAssertEqual(manifest.name, "Trivial")
                }
            }
        }
    }

    func testNonTrivialManifestLoading_X1() {
        let N = 1
        let manifest = ByteString(encodingAsUTF8: """
            import PackageDescription
            let package = Package(
                name: "Foo",
                dependencies: [
                    .package(url: "https://example.com/example", from: "1.0.0")
                ],
                targets: [
                    .target(name: "sys", dependencies: ["libc"]),
                    .target(name: "dep", dependencies: ["sys", "libc"])
                ]
            )
            """)

        write(manifest) { path in
            measure {
                for _ in 0..<N {
                    let manifest = try! self.manifestLoader.load(package: path, baseURL: "/", manifestVersion: .v4)
                    XCTAssertEqual(manifest.name, "Foo")
                }
            }
        }
    }
}<commit_msg>[PerfTests] Fix two perf tests<commit_after>/*
 This source file is part of the Swift.org open source project

 Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
 Licensed under Apache License v2.0 with Runtime Library Exception

 See http://swift.org/LICENSE.txt for license information
 See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import XCTest

import Basic
import TestSupport
import PackageLoading

class ManifestLoadingPerfTests: XCTestCasePerf {
    let manifestLoader = ManifestLoader(manifestResources: Resources.default)

    func write(_ bytes: ByteString, body: (AbsolutePath) -> ()) {
        mktmpdir { path in
            let manifestFile = path.appending(component: "Package.swift")
            try localFileSystem.writeFileContents(manifestFile, bytes: bytes)
            body(path)
        }
    }

    func testTrivialManifestLoading_X1() {
        let N = 1
        let trivialManifest = ByteString(encodingAsUTF8: ("""
            import PackageDescription
            let package = Package(name: "Trivial")
            """))
        write(trivialManifest) { path in
            measure {
                for _ in 0..<N {
                    let manifest = try! self.manifestLoader.load(package: path, baseURL: "/Trivial", manifestVersion: .v4)
                    XCTAssertEqual(manifest.name, "Trivial")
                }
            }
        }
    }

    func testNonTrivialManifestLoading_X1() {
        let N = 1
        let manifest = ByteString(encodingAsUTF8: """
            import PackageDescription
            let package = Package(
                name: "Foo",
                dependencies: [
                    .package(url: "https://example.com/example", from: "1.0.0")
                ],
                targets: [
                    .target(name: "sys", dependencies: ["libc"]),
                    .target(name: "dep", dependencies: ["sys", "libc"])
                ]
            )
            """)

        write(manifest) { path in
            measure {
                for _ in 0..<N {
                    let manifest = try! self.manifestLoader.load(package: path, baseURL: "/Trivial", manifestVersion: .v4)
                    XCTAssertEqual(manifest.name, "Foo")
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.0984898227183191, 'fraction_numerical': 0.010067848544539286, 'mean_word_length': 1.778115501519757, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1791315', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1154, 'n_words': 314}