Skip to content

Commit c3eb411

Browse files
committed
Add performance measurement with instructions count
1 parent b556ac7 commit c3eb411

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ let package = Package(
290290

291291
.testTarget(
292292
name: "PerformanceTest",
293-
dependencies: ["SwiftIDEUtils", "SwiftParser", "SwiftSyntax"],
293+
dependencies: ["_InstructionCounter", "SwiftIDEUtils", "SwiftParser", "SwiftSyntax"],
294294
exclude: ["Inputs"]
295295
),
296296
]

Tests/PerformanceTest/ParsingPerformanceTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class ParsingPerformanceTests: XCTestCase {
2525

2626
func testNativeParsingPerformance() throws {
2727
try XCTSkipIf(ProcessInfo.processInfo.environment["SKIP_LONG_TESTS"] == "1")
28-
measure {
28+
measureInscructions(baseline: 5_850_081_534) {
2929
do {
3030
let source = try String(contentsOf: inputFile)
3131
_ = Parser.parse(source: source)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import XCTest
14+
import _InstructionCounter
15+
16+
extension XCTestCase {
17+
func measureInscructions(baseline: UInt64, block: () -> Void, file: StaticString = #file, line: UInt = #line) {
18+
let startInstructions = getInstructionsExecuted()
19+
block()
20+
let endInstructions = getInstructionsExecuted()
21+
let numberOfInstructions = endInstructions - startInstructions
22+
23+
let lowerBaseline = UInt64(Double(baseline) * 0.97)
24+
let upperBaseline = UInt64(Double(baseline) * 1.03)
25+
let baselineRange = lowerBaseline...upperBaseline
26+
27+
XCTAssertTrue(
28+
baselineRange.contains(numberOfInstructions),
29+
"""
30+
Number of instructions '\(numberOfInstructions)'
31+
is not within range \(lowerBaseline)-\(upperBaseline)
32+
""",
33+
file: file,
34+
line: line
35+
)
36+
}
37+
}

0 commit comments

Comments
 (0)