Skip to content

[swift/main] Update swift main #607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 44 commits into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
49c1d8c
Add option to show benchmark charts
rxwei Jul 16, 2022
6ca5cfd
Add new comparison features
rctcwyvrn Jul 27, 2022
74dd8e6
Add loading
rctcwyvrn Jul 27, 2022
662870e
Accidently flipped the order
rctcwyvrn Jul 27, 2022
1b761be
Disable compile time comparisons by default
rctcwyvrn Jul 27, 2022
f897844
Rename builder parameter name
Azoy Aug 1, 2022
9762399
Merge pull request #593 from Azoy/param-names
Azoy Aug 1, 2022
1b7779a
Remove `re'...'` and `rx'...'` delimiters
hamishknight Aug 2, 2022
415b080
Merge pull request #594 from hamishknight/limited-edition
hamishknight Aug 2, 2022
e8d273a
Change chart to be a normalized performance graph
rctcwyvrn Aug 3, 2022
2c12236
Add compile time measurement + cleanup
rctcwyvrn Aug 3, 2022
1f6010c
Oops
rctcwyvrn Aug 3, 2022
a0af345
Add enum for comparison type
rctcwyvrn Aug 3, 2022
405fbcb
Implement instructions for matching builtin character classes and ass…
rctcwyvrn Aug 3, 2022
1acca94
[Optimization] Specialized quantification instruction (#577)
rctcwyvrn Aug 3, 2022
b7b23d3
Add instructions for consuming non-newlines and advancing in scalar view
rctcwyvrn Aug 3, 2022
aff32e6
Merge branch 'main' into charts-and-compares
rctcwyvrn Aug 3, 2022
1f76eb9
Fix matching of backreferences in scalar mode
rctcwyvrn Aug 4, 2022
aa81037
Add canImport for CI
rctcwyvrn Aug 4, 2022
8cdc76e
Add compiler options for tracing and metrics
rctcwyvrn Aug 4, 2022
8101f55
Add metrics + update tracing
rctcwyvrn Jul 20, 2022
b9f68c8
Enable metrics and tracing on the benchmarker
rctcwyvrn Aug 5, 2022
4b107a8
Fix tracing
rctcwyvrn Aug 5, 2022
9062855
Cleanup benchmark protocols
rctcwyvrn Aug 5, 2022
b2a49f9
Add parse time measurement + cleanup benchmarker
rctcwyvrn Aug 5, 2022
1de8128
Call parse directly
rctcwyvrn Aug 5, 2022
205e4d3
Make comparison generic + Adjust stdev requirement to be a %
rctcwyvrn Aug 5, 2022
ec7727b
Merge pull request #597 from rctcwyvrn/backreference-in-scalar-mode
rctcwyvrn Aug 10, 2022
ceecaaa
Merge pull request #596 from rctcwyvrn/consume-non-newline
rctcwyvrn Aug 10, 2022
82f71dd
Cleanup
rctcwyvrn Aug 10, 2022
a99b333
Backreferences do not guarantee forward progress
rctcwyvrn Aug 11, 2022
caa082e
Merge pull request #598 from rctcwyvrn/thanks-fuzzer
rctcwyvrn Aug 15, 2022
3d0789f
Cleanup
rctcwyvrn Aug 15, 2022
9c8e567
Add conditional compilation for metric measuring
rctcwyvrn Aug 15, 2022
dbcb7fd
Fix spacing
rctcwyvrn Aug 15, 2022
c2b672f
Fix ns suffix mismatch
rctcwyvrn Aug 15, 2022
68f8845
Merge pull request #595 from rctcwyvrn/charts-and-compares
rctcwyvrn Aug 15, 2022
fc36828
Don't assume quoted literals are non-empty during bytecodegen
rctcwyvrn Aug 15, 2022
1c8702f
Merge pull request #600 from rctcwyvrn/oh-no-i-was-dumb
rctcwyvrn Aug 15, 2022
d1cfc4e
Deprecate `Regex.init(quoting:)`
hamishknight Aug 16, 2022
b7bcb32
Merge pull request #602 from hamishknight/quote-overload
hamishknight Aug 16, 2022
a220bef
Update cmake file list
Azoy Aug 24, 2022
7a10c81
Merge pull request #606 from Azoy/cmake-cmake-cmake
Azoy Aug 24, 2022
635237c
Merge remote-tracking branch 'origin/main' into swift/main
milseman Aug 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
add_subdirectory(RegexBuilder)
add_subdirectory(_RegexParser)
add_subdirectory(_StringProcessing)
add_subdirectory(Prototypes)
add_subdirectory(VariadicsGenerator)
66 changes: 52 additions & 14 deletions Sources/RegexBenchmark/Benchmark.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,45 @@
import _StringProcessing
@_spi(RegexBenchmark) import _StringProcessing
@_implementationOnly import _RegexParser
import Foundation

protocol RegexBenchmark {
protocol RegexBenchmark: Debug {
var name: String { get }
func run()
func debug()
}

struct Benchmark: RegexBenchmark {
protocol SwiftRegexBenchmark: RegexBenchmark {
var regex: Regex<AnyRegexOutput> { get set }
var pattern: String? { get }
}

extension SwiftRegexBenchmark {
mutating func compile() {
let _ = regex._forceAction(.recompile)
}
mutating func parse() -> Bool {
guard let s = pattern else {
return false
}

do {
let _ = try _RegexParser.parse(s, .traditional)
return true
} catch {
return false
}
}
mutating func enableTracing() {
let _ = regex._forceAction(.addOptions(.enableTracing))
}
mutating func enableMetrics() {
let _ = regex._forceAction(.addOptions([.enableMetrics]))
}
}

struct Benchmark: SwiftRegexBenchmark {
let name: String
let regex: Regex<AnyRegexOutput>
var regex: Regex<AnyRegexOutput>
let pattern: String?
let type: MatchType
let target: String

Expand Down Expand Up @@ -52,11 +82,12 @@ struct NSBenchmark: RegexBenchmark {
}

/// A benchmark running a regex on strings in input set
struct InputListBenchmark: RegexBenchmark {
struct InputListBenchmark: SwiftRegexBenchmark {
let name: String
let regex: Regex<AnyRegexOutput>
var regex: Regex<AnyRegexOutput>
let pattern: String?
let targets: [String]

func run() {
for target in targets {
blackHole(target.wholeMatch(of: regex))
Expand All @@ -78,7 +109,7 @@ struct InputListNSBenchmark: RegexBenchmark {
func range(in target: String) -> NSRange {
NSRange(target.startIndex..<target.endIndex, in: target)
}

func run() {
for target in targets {
let range = range(in: target)
Expand All @@ -89,6 +120,9 @@ struct InputListNSBenchmark: RegexBenchmark {

/// A benchmark meant to be ran across multiple engines
struct CrossBenchmark {
/// Suffix added onto NSRegularExpression benchmarks
static var nsSuffix: String { "_NS" }

/// The base name of the benchmark
var baseName: String

Expand Down Expand Up @@ -123,11 +157,12 @@ struct CrossBenchmark {
Benchmark(
name: baseName + "Whole",
regex: swiftRegex,
pattern: regex,
type: .whole,
target: input))
runner.register(
NSBenchmark(
name: baseName + "Whole_NS",
name: baseName + "Whole" + CrossBenchmark.nsSuffix,
regex: nsRegex,
type: .first,
target: input))
Expand All @@ -136,24 +171,26 @@ struct CrossBenchmark {
Benchmark(
name: baseName + "All",
regex: swiftRegex,
pattern: regex,
type: .allMatches,
target: input))
runner.register(
NSBenchmark(
name: baseName + "All_NS",
name: baseName + "All" + CrossBenchmark.nsSuffix,
regex: nsRegex,
type: .allMatches,
target: input))
if includeFirst {
if includeFirst || runner.includeFirstOverride {
runner.register(
Benchmark(
name: baseName + "First",
regex: swiftRegex,
pattern: regex,
type: .first,
target: input))
runner.register(
NSBenchmark(
name: baseName + "First_NS",
name: baseName + "First" + CrossBenchmark.nsSuffix,
regex: nsRegex,
type: .first,
target: input))
Expand All @@ -178,10 +215,11 @@ struct CrossInputListBenchmark {
runner.register(InputListBenchmark(
name: baseName,
regex: swiftRegex,
pattern: regex,
targets: inputs
))
runner.register(InputListNSBenchmark(
name: baseName + "NS",
name: baseName + CrossBenchmark.nsSuffix,
regex: regex,
targets: inputs
))
Expand Down
80 changes: 80 additions & 0 deletions Sources/RegexBenchmark/BenchmarkChart.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

#if os(macOS) && canImport(Charts)

import Charts
import SwiftUI

struct BenchmarkChart: View {
var comparisons: [BenchmarkResult.Comparison]

// Sort by normalized difference
var sortedComparisons: [BenchmarkResult.Comparison] {
comparisons.sorted { a, b in
a.normalizedDiff < b.normalizedDiff
}
}
var body: some View {
VStack(alignment: .leading) {
Chart {
ForEach(sortedComparisons) { comparison in
// Normalized runtime
BarMark(
x: .value("Name", comparison.name),
y: .value("Normalized runtime", comparison.normalizedDiff))
.foregroundStyle(LinearGradient(
colors: [.accentColor, comparison.diff?.seconds ?? 0 <= 0 ? .green : .yellow],
startPoint: .bottom,
endPoint: .top))
}
// Baseline
RuleMark(y: .value("Time", 1.0))
.foregroundStyle(.red)
.lineStyle(.init(lineWidth: 1, dash: [2]))
.annotation(position: .top, alignment: .leading) {
Text("Baseline").foregroundStyle(.red)
}

}
.frame(idealWidth: 800, idealHeight: 800)
.chartYScale(domain: 0...2.0)
.chartYAxis {
AxisMarks(values: .stride(by: 0.1))
}
.chartXAxis {
AxisMarks { value in
AxisGridLine()
AxisTick()
AxisValueLabel(value.as(String.self)!, orientation: .vertical)
}
}
}
}
}

struct BenchmarkResultApp: App {
static var comparisons: [BenchmarkResult.Comparison]?

var body: some Scene {
WindowGroup {
if let comparisons = Self.comparisons {
ScrollView {
BenchmarkChart(comparisons: comparisons)
}
} else {
Text("No data")
}
}
}
}

#endif
35 changes: 15 additions & 20 deletions Sources/RegexBenchmark/BenchmarkRegistration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,22 @@
// Do not remove the start of registration or end of registration markers

extension BenchmarkRunner {
static func makeRunner(
_ samples: Int,
_ quiet: Bool
) -> BenchmarkRunner {
var benchmark = BenchmarkRunner("RegexBench", samples, quiet)
mutating func registerDefault() {
// -- start of registrations --
benchmark.addReluctantQuant()
benchmark.addCSS()
benchmark.addNotFound()
benchmark.addGraphemeBreak()
benchmark.addHangulSyllable()
// benchmark.addHTML() // Disabled due to \b being unusably slow
benchmark.addEmail()
benchmark.addCustomCharacterClasses()
benchmark.addBuiltinCC()
benchmark.addUnicode()
benchmark.addLiteralSearch()
benchmark.addDiceNotation()
benchmark.addErrorMessages()
benchmark.addIpAddress()
self.addReluctantQuant()
self.addCSS()
self.addNotFound()
self.addGraphemeBreak()
self.addHangulSyllable()
// self.addHTML() // Disabled due to \b being unusably slow
self.addEmail()
self.addCustomCharacterClasses()
self.addBuiltinCC()
self.addUnicode()
self.addLiteralSearch()
self.addDiceNotation()
self.addErrorMessages()
self.addIpAddress()
// -- end of registrations --
return benchmark
}
}
Loading