From b1a96e863d8e02e5d905824ba3f32051dc152378 Mon Sep 17 00:00:00 2001 From: Keita Nonaka Date: Tue, 7 May 2019 18:29:24 -0400 Subject: [PATCH 1/4] Variants for Set Sequence Methods --- benchmark/single-source/SetTests.swift | 559 ++++++++++++++++++++++++- 1 file changed, 558 insertions(+), 1 deletion(-) diff --git a/benchmark/single-source/SetTests.swift b/benchmark/single-source/SetTests.swift index a6d4b45799c82..5f5bc6ccf902a 100644 --- a/benchmark/single-source/SetTests.swift +++ b/benchmark/single-source/SetTests.swift @@ -55,6 +55,41 @@ let setQ: Set = { return set }() +// Construction of empty array. +let arrayE: Array = [] +let arrayOE: Array> = [] + +// Construction kit for arrays with 25% overlap +let arrayAB = Array(0 ..< size) // 0 ..< 400 +let arrayCD = Array(size ..< 2 * size) // 400 ..< 800 +let arrayBC = Array(size - quarter ..< 2 * size - quarter) // 300 ..< 700 +let arrayB = Array(size - quarter ..< size) // 300 ..< 400 + +let arrayOAB = arrayAB.map(Box.init) +let arrayOCD = arrayCD.map(Box.init) +let arrayOBC = arrayBC.map(Box.init) +let arrayOB = arrayB.map(Box.init) + +// Construction kit for arrays with 50% overlap +let arrayXY = Array(0 ..< size) // 0 ..< 400 +let arrayYZ = Array(half ..< size + half) // 200 ..< 600 +let arrayY = Array(half ..< size) // 200 ..< 400 + +let arrayP = Array(0 ..< size) + +// Construction of flexible sets. +var set: Set = [] +var setBox: Set> = [] + +func set(_ size: Int) { + set = Set(0 ..< size) +} + +func setBox(_ size: Int) { + setBox = Set(Set(0 ..< size).map(Box.init)) +} + + public let SetTests = [ // Mnemonic: number after name is percentage of common elements in input sets. BenchmarkInfo( @@ -98,6 +133,47 @@ public let SetTests = [ tags: [.validation, .api, .Set], setUpFunction: { blackHole([setP, setQ]) }), + BenchmarkInfo( + name: "Set.isSubset.Seq.Empty.Int", + runFunction: { n in run_SetIsSubsetSeqInt(setE, arrayAB, true, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setE, arrayAB]) }), + BenchmarkInfo( + name: "Set.isSubset.Seq.Int.Empty", + runFunction: { n in run_SetIsSubsetSeqInt(setAB, arrayE, false, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayE]) }), + BenchmarkInfo( + name: "Set.isSubset.Seq.Int0", + runFunction: { n in run_SetIsSubsetSeqInt(setAB, arrayCD, false, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayCD]) }), + BenchmarkInfo( + name: "Set.isSubset.Seq.Box0", + runFunction: { n in run_SetIsSubsetSeqBox(setOAB, arrayOCD, false, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOAB, arrayOCD]) }), + BenchmarkInfo( + name: "Set.isSubset.Seq.Int25", + runFunction: { n in run_SetIsSubsetSeqInt(setB, arrayAB, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setB, arrayAB]) }), + BenchmarkInfo( + name: "Set.isSubset.Seq.Box25", + runFunction: { n in run_SetIsSubsetSeqBox(setOB, arrayOAB, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOB, arrayOAB]) }), + BenchmarkInfo( + name: "Set.isSubset.Seq.Int50", + runFunction: { n in run_SetIsSubsetSeqInt(setY, arrayXY, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setY, arrayXY]) }), + BenchmarkInfo( + name: "Set.isSubset.Seq.Int100", + runFunction: { n in run_SetIsSubsetSeqInt(setP, arrayP, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setP, arrayP]) }), + BenchmarkInfo( name: "Set.isStrictSubset.Empty.Int", runFunction: { n in run_SetIsStrictSubsetInt(setE, setAB, true, 5000 * n) }, @@ -135,10 +211,133 @@ public let SetTests = [ setUpFunction: { blackHole([setY, setXY]) }), BenchmarkInfo( name: "Set.isStrictSubset.Int100", - runFunction: { n in run_SetIsStrictSubsetInt(setP, setQ, false, 50 * n) }, + runFunction: { n in run_SetIsStrictSubsetInt(setP, setQ, false, 5000 * n) }, tags: [.validation, .api, .Set], setUpFunction: { blackHole([setP, setQ]) }), + BenchmarkInfo( + name: "Set.isStrictSubset.Seq.Empty.Int", + runFunction: { n in run_SetIsStrictSubsetSeqInt(setE, arrayAB, true, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setE, arrayAB]) }), + BenchmarkInfo( + name: "Set.isStrictSubset.Seq.Int.Empty", + runFunction: { n in run_SetIsStrictSubsetSeqInt(setAB, arrayE, false, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayE]) }), + BenchmarkInfo( + name: "Set.isStrictSubset.Seq.Int0", + runFunction: { n in run_SetIsStrictSubsetSeqInt(setAB, arrayCD, false, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayCD]) }), + BenchmarkInfo( + name: "Set.isStrictSubset.Seq.Box0", + runFunction: { n in run_SetIsStrictSubsetSeqBox(setOAB, arrayOCD, false, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOAB, arrayOCD]) }), + BenchmarkInfo( + name: "Set.isStrictSubset.Seq.Int25", + runFunction: { n in run_SetIsStrictSubsetSeqInt(setB, arrayAB, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setB, arrayAB]) }), + BenchmarkInfo( + name: "Set.isStrictSubset.Seq.Box25", + runFunction: { n in run_SetIsStrictSubsetSeqBox(setOB, arrayOAB, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOB, arrayOAB]) }), + BenchmarkInfo( + name: "Set.isStrictSubset.Seq.Int50", + runFunction: { n in run_SetIsStrictSubsetSeqInt(setY, arrayXY, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setY, arrayXY]) }), + BenchmarkInfo( + name: "Set.isStrictSubset.Seq.Int100", + runFunction: { n in run_SetIsStrictSubsetSeqInt(setP, arrayP, false, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setP, arrayP]) }), + + BenchmarkInfo( + name: "Set.isSuperset.Seq.Empty.Int", + runFunction: { n in run_SetIsSupersetSeqInt(setAB, arrayE, true, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayE]) }), + BenchmarkInfo( + name: "Set.isSuperset.Seq.Int.Empty", + runFunction: { n in run_SetIsSupersetSeqInt(setE, arrayAB, false, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setE, arrayAB]) }), + BenchmarkInfo( + name: "Set.isSuperset.Seq.Int0", + runFunction: { n in run_SetIsSupersetSeqInt(setCD, arrayAB, false, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setCD, arrayAB]) }), + BenchmarkInfo( + name: "Set.isSuperset.Seq.Box0", + runFunction: { n in run_SetIsSupersetSeqBox(setOCD, arrayOAB, false, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOCD, arrayOAB]) }), + BenchmarkInfo( + name: "Set.isSuperset.Seq.Int25", + runFunction: { n in run_SetIsSupersetSeqInt(setAB, arrayB, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayB]) }), + BenchmarkInfo( + name: "Set.isSuperset.Seq.Box25", + runFunction: { n in run_SetIsSupersetSeqBox(setOAB, arrayOB, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOAB, arrayOB]) }), + BenchmarkInfo( + name: "Set.isSuperset.Seq.Int50", + runFunction: { n in run_SetIsSupersetSeqInt(setXY, arrayY, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setXY, arrayY]) }), + BenchmarkInfo( + name: "Set.isSuperset.Seq.Int100", + runFunction: { n in run_SetIsSupersetSeqInt(setP, arrayP, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setP, arrayP]) }), + + BenchmarkInfo( + name: "Set.isStrictSuperset.Seq.Empty.Int", + runFunction: { n in run_SetIsStrictSupersetSeqInt(setAB, arrayE, true, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayE]) }), + BenchmarkInfo( + name: "Set.isStrictSuperset.Seq.Int.Empty", + runFunction: { n in run_SetIsStrictSupersetSeqInt(setE, arrayAB, false, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setE, arrayAB]) }), + BenchmarkInfo( + name: "Set.isStrictSuperset.Seq.Int0", + runFunction: { n in run_SetIsStrictSupersetSeqInt(setCD, arrayAB, false, 500 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setCD, arrayAB]) }), + BenchmarkInfo( + name: "Set.isStrictSuperset.Seq.Box0", + runFunction: { n in run_SetIsStrictSupersetSeqBox(setOCD, arrayOAB, false, 500 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOCD, arrayOAB]) }), + BenchmarkInfo( + name: "Set.isStrictSuperset.Seq.Int25", + runFunction: { n in run_SetIsStrictSupersetSeqInt(setAB, arrayB, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayB]) }), + BenchmarkInfo( + name: "Set.isStrictSuperset.Seq.Box25", + runFunction: { n in run_SetIsStrictSupersetSeqBox(setOAB, arrayOB, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOAB, arrayOB]) }), + BenchmarkInfo( + name: "Set.isStrictSuperset.Seq.Int50", + runFunction: { n in run_SetIsStrictSupersetSeqInt(setXY, arrayY, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setXY, arrayY]) }), + BenchmarkInfo( + name: "Set.isStrictSuperset.Seq.Int100", + runFunction: { n in run_SetIsStrictSupersetSeqInt(setP, arrayP, false, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setP, arrayP]) }), + BenchmarkInfo( name: "Set.isDisjoint.Empty.Int", runFunction: { n in run_SetIsDisjointInt(setE, setAB, true, 5000 * n) }, @@ -190,6 +389,57 @@ public let SetTests = [ tags: [.validation, .api, .Set], setUpFunction: { blackHole([setP, setQ]) }), + BenchmarkInfo( + name: "Set.isDisjoint.Seq.Empty.Int", + runFunction: { n in run_SetIsDisjointSeqInt(setE, arrayAB, true, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setE, arrayAB]) }), + BenchmarkInfo( + name: "Set.isDisjoint.Seq.Int.Empty", + runFunction: { n in run_SetIsDisjointSeqInt(setAB, arrayE, true, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayE]) }), + BenchmarkInfo( + name: "Set.isDisjoint.Seq.Empty.Box", + runFunction: { n in run_SetIsDisjointSeqBox(setOE, arrayOAB, true, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOE, arrayOAB]) }), + BenchmarkInfo( + name: "Set.isDisjoint.Seq.Box.Empty", + runFunction: { n in run_SetIsDisjointSeqBox(setOAB, arrayOE, true, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOAB, arrayOE]) }), + BenchmarkInfo( + name: "Set.isDisjoint.Seq.Int0", + runFunction: { n in run_SetIsDisjointSeqInt(setAB, arrayCD, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayCD]) }), + BenchmarkInfo( + name: "Set.isDisjoint.Seq.Box0", + runFunction: { n in run_SetIsDisjointSeqBox(setOAB, arrayOCD, true, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOAB, arrayOCD]) }), + BenchmarkInfo( + name: "Set.isDisjoint.Seq.Int25", + runFunction: { n in run_SetIsDisjointSeqInt(setB, arrayAB, false, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setB, arrayAB]) }), + BenchmarkInfo( + name: "Set.isDisjoint.Seq.Box25", + runFunction: { n in run_SetIsDisjointSeqBox(setOB, arrayOAB, false, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOB, arrayOAB]) }), + BenchmarkInfo( + name: "Set.isDisjoint.Seq.Int50", + runFunction: { n in run_SetIsDisjointSeqInt(setY, arrayXY, false, 50 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setY, arrayXY]) }), + BenchmarkInfo( + name: "Set.isDisjoint.Seq.Int100", + runFunction: { n in run_SetIsDisjointSeqInt(setP, arrayP, false, 5000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setP, arrayP]) }), + BenchmarkInfo( name: "SetSymmetricDifferenceInt0", runFunction: { n in run_SetSymmetricDifferenceInt(setAB, setCD, countABCD, 10 * n) }, @@ -252,6 +502,37 @@ public let SetTests = [ tags: [.validation, .api, .Set], setUpFunction: { blackHole([setP, setQ]) }), + BenchmarkInfo( + name: "Set.intersection.Seq.Int0", + runFunction: { n in run_SetIntersectionSeqInt(setAB, arrayCD, 0, 10 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayCD]) }), + BenchmarkInfo( + name: "Set.intersection.Seq.Box0", + runFunction: { n in run_SetIntersectionSeqBox(setOAB, arrayOCD, 0, 10 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOAB, arrayOCD]) }), + BenchmarkInfo( + name: "Set.intersection.Seq.Int25", + runFunction: { n in run_SetIntersectionSeqInt(setAB, arrayBC, countB, 10 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayBC]) }), + BenchmarkInfo( + name: "Set.intersection.Seq.Box25", + runFunction: { n in run_SetIntersectionSeqBox(setOAB, arrayOBC, countB, 10 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOAB, arrayOBC]) }), + BenchmarkInfo( + name: "Set.intersection.Seq.Int50", + runFunction: { n in run_SetIntersectionSeqInt(setXY, arrayYZ, half, 10 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setXY, arrayYZ]) }), + BenchmarkInfo( + name: "Set.intersection.Seq.Int100", + runFunction: { n in run_SetIntersectionSeqInt(setP, arrayP, size, 10 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setP, arrayP]) }), + BenchmarkInfo( name: "SetUnionInt0", runFunction: { n in run_SetUnionInt(setAB, setCD, countABCD, 10 * n) }, @@ -334,6 +615,98 @@ public let SetTests = [ tags: [.validation, .api, .Set], setUpFunction: { blackHole([setP, setQ]) }), + BenchmarkInfo( + name: "Set.subtracting.Seq.Empty.Int", + runFunction: { n in run_SetSubtractingSeqInt(setE, arrayAB, 0, 1000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setE, arrayAB]) }), + BenchmarkInfo( + name: "Set.subtracting.Seq.Int.Empty", + runFunction: { n in run_SetSubtractingSeqInt(setAB, arrayE, countAB, 1000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayE]) }), + BenchmarkInfo( + name: "Set.subtracting.Seq.Empty.Box", + runFunction: { n in run_SetSubtractingSeqBox(setOE, arrayOAB, 0, 1000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOE, arrayOAB]) }), + BenchmarkInfo( + name: "Set.subtracting.Seq.Box.Empty", + runFunction: { n in run_SetSubtractingSeqBox(setOAB, arrayOE, countAB, 1000 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOAB, arrayOE]) }), + BenchmarkInfo( + name: "Set.subtracting.Seq.Int0", + runFunction: { n in run_SetSubtractingSeqInt(setAB, arrayCD, countAB, 10 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayCD]) }), + BenchmarkInfo( + name: "Set.subtracting.Seq.Box0", + runFunction: { n in run_SetSubtractingSeqBox(setOAB, arrayOCD, countAB, 10 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOAB, arrayOCD]) }), + BenchmarkInfo( + name: "Set.subtracting.Seq.Int25", + runFunction: { n in run_SetSubtractingSeqInt(setAB, arrayBC, countA, 10 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setAB, arrayBC]) }), + BenchmarkInfo( + name: "Set.subtracting.Seq.Box25", + runFunction: { n in run_SetSubtractingSeqBox(setOAB, arrayOBC, countA, 10 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setOAB, arrayOBC]) }), + BenchmarkInfo( + name: "Set.subtracting.Seq.Int50", + runFunction: { n in run_SetSubtractingSeqInt(setXY, arrayYZ, half, 10 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setXY, arrayYZ]) }), + BenchmarkInfo( + name: "Set.subtracting.Seq.Int100", + runFunction: { n in run_SetSubtractingSeqInt(setP, arrayP, 0, 10 * n) }, + tags: [.validation, .api, .Set], + setUpFunction: { blackHole([setP, arrayP]) }), + + BenchmarkInfo( + name: "Set.filter.Int50.16k", + runFunction: { n in run_SetFilterInt50(n) }, + tags: [.validation, .api, .Set], + setUpFunction: { set(16_000) }), + BenchmarkInfo( + name: "Set.filter.Int50.20k", + runFunction: { n in run_SetFilterInt50(n) }, + tags: [.validation, .api, .Set], + setUpFunction: { set(20_000) }), + BenchmarkInfo( + name: "Set.filter.Int50.24k", + runFunction: { n in run_SetFilterInt50(n) }, + tags: [.validation, .api, .Set], + setUpFunction: { set(24_000) }), + BenchmarkInfo( + name: "Set.filter.Int50.28k", + runFunction: { n in run_SetFilterInt50(n) }, + tags: [.validation, .api, .Set], + setUpFunction: { set(28_000) }), + BenchmarkInfo( + name: "Set.filter.Int100.16k", + runFunction: { n in run_SetFilterInt100(n) }, + tags: [.validation, .api, .Set], + setUpFunction: { set(16_000) }), + BenchmarkInfo( + name: "Set.filter.Int100.20k", + runFunction: { n in run_SetFilterInt100(n) }, + tags: [.validation, .api, .Set], + setUpFunction: { set(20_000) }), + BenchmarkInfo( + name: "Set.filter.Int100.24k", + runFunction: { n in run_SetFilterInt100(n) }, + tags: [.validation, .api, .Set], + setUpFunction: { set(24_000) }), + BenchmarkInfo( + name: "Set.filter.Int100.28k", + runFunction: { n in run_SetFilterInt100(n) }, + tags: [.validation, .api, .Set], + setUpFunction: { set(28_000) }), + // Legacy benchmarks, kept for continuity with previous releases. BenchmarkInfo( name: "SetExclusiveOr", // ~"SetSymmetricDifferenceInt0" @@ -374,6 +747,18 @@ public func run_SetIsSubsetInt( } } +@inline(never) +public func run_SetIsSubsetSeqInt( + _ a: Set, + _ b: Array, + _ r: Bool, + _ n: Int) { + for _ in 0 ..< n { + let isSubset = a.isSubset(of: identity(b)) + CheckResults(isSubset == r) + } +} + @inline(never) public func run_SetIsStrictSubsetInt( _ a: Set, @@ -386,6 +771,42 @@ public func run_SetIsStrictSubsetInt( } } +@inline(never) +public func run_SetIsStrictSubsetSeqInt( + _ a: Set, + _ b: Array, + _ r: Bool, + _ n: Int) { + for _ in 0 ..< n { + let isStrictSubset = a.isStrictSubset(of: identity(b)) + CheckResults(isStrictSubset == r) + } +} + +@inline(never) +public func run_SetIsSupersetSeqInt( + _ a: Set, + _ b: Array, + _ r: Bool, + _ n: Int) { + for _ in 0 ..< n { + let isSuperset = a.isSuperset(of: identity(b)) + CheckResults(isSuperset == r) + } +} + +@inline(never) +public func run_SetIsStrictSupersetSeqInt( + _ a: Set, + _ b: Array, + _ r: Bool, + _ n: Int) { + for _ in 0 ..< n { + let isStrictSuperset = a.isStrictSuperset(of: identity(b)) + CheckResults(isStrictSuperset == r) + } +} + @inline(never) public func run_SetSymmetricDifferenceInt( _ a: Set, @@ -422,6 +843,18 @@ public func run_SetIntersectionInt( } } +@inline(never) +public func run_SetIntersectionSeqInt( + _ a: Set, + _ b: Array, + _ r: Int, + _ n: Int) { + for _ in 0 ..< n { + let and = a.intersection(identity(b)) + CheckResults(and.count == r) + } +} + @inline(never) public func run_SetSubtractingInt( _ a: Set, @@ -434,6 +867,18 @@ public func run_SetSubtractingInt( } } +@inline(never) +public func run_SetSubtractingSeqInt( + _ a: Set, + _ b: Array, + _ r: Int, + _ n: Int) { + for _ in 0 ..< n { + let and = a.subtracting(identity(b)) + CheckResults(and.count == r) + } +} + @inline(never) public func run_SetIsDisjointInt( _ a: Set, @@ -446,6 +891,34 @@ public func run_SetIsDisjointInt( } } +@inline(never) +public func run_SetIsDisjointSeqInt( + _ a: Set, + _ b: Array, + _ r: Bool, + _ n: Int) { + for _ in 0 ..< n { + let isDisjoint = a.isDisjoint(with: identity(b)) + CheckResults(isDisjoint == r) + } +} + +@inline(never) +public func run_SetFilterInt50(_ n: Int) { + for _ in 0 ..< n { + let half = set.filter { $0 % 2 == 0 } + CheckResults(set.count == half.count * 2) + } +} + +@inline(never) +public func run_SetFilterInt100(_ n: Int) { + for _ in 0 ..< n { + let copy = set.filter { _ in true } + CheckResults(set.count == copy.count) + } +} + class Box : Hashable { var value: T @@ -474,6 +947,18 @@ func run_SetIsSubsetBox( } } +@inline(never) +func run_SetIsSubsetSeqBox( + _ a: Set>, + _ b: Array>, + _ r: Bool, + _ n: Int) { + for _ in 0 ..< n { + let isSubset = a.isSubset(of: identity(b)) + CheckResults(isSubset == r) + } +} + @inline(never) func run_SetIsStrictSubsetBox( _ a: Set>, @@ -486,6 +971,42 @@ func run_SetIsStrictSubsetBox( } } +@inline(never) +func run_SetIsStrictSubsetSeqBox( + _ a: Set>, + _ b: Array>, + _ r: Bool, + _ n: Int) { + for _ in 0 ..< n { + let isStrictSubset = a.isStrictSubset(of: identity(b)) + CheckResults(isStrictSubset == r) + } +} + +@inline(never) +func run_SetIsSupersetSeqBox( + _ a: Set>, + _ b: Array>, + _ r: Bool, + _ n: Int) { + for _ in 0 ..< n { + let isSuperset = a.isSuperset(of: identity(b)) + CheckResults(isSuperset == r) + } +} + +@inline(never) +func run_SetIsStrictSupersetSeqBox( + _ a: Set>, + _ b: Array>, + _ r: Bool, + _ n: Int) { + for _ in 0 ..< n { + let isStrictSuperset = a.isStrictSuperset(of: identity(b)) + CheckResults(isStrictSuperset == r) + } +} + @inline(never) func run_SetSymmetricDifferenceBox( _ a: Set>, @@ -522,6 +1043,18 @@ func run_SetIntersectionBox( } } +@inline(never) +func run_SetIntersectionSeqBox( + _ a: Set>, + _ b: Array>, + _ r: Int, + _ n: Int) { + for _ in 0 ..< n { + let and = a.intersection(identity(b)) + CheckResults(and.count == r) + } +} + @inline(never) func run_SetSubtractingBox( _ a: Set>, @@ -534,6 +1067,18 @@ func run_SetSubtractingBox( } } +@inline(never) +func run_SetSubtractingSeqBox( + _ a: Set>, + _ b: Array>, + _ r: Int, + _ n: Int) { + for _ in 0 ..< n { + let and = a.subtracting(identity(b)) + CheckResults(and.count == r) + } +} + @inline(never) func run_SetIsDisjointBox( _ a: Set>, @@ -545,3 +1090,15 @@ func run_SetIsDisjointBox( CheckResults(isDisjoint == r) } } + +@inline(never) +func run_SetIsDisjointSeqBox( + _ a: Set>, + _ b: Array>, + _ r: Bool, + _ n: Int) { + for _ in 0 ..< n { + let isDisjoint = a.isDisjoint(with: identity(b)) + CheckResults(isDisjoint == r) + } +} From cecbb1491e62c467a27a3defc1a2724bf84b9ddb Mon Sep 17 00:00:00 2001 From: Keita Nonaka Date: Fri, 10 May 2019 14:43:42 -0400 Subject: [PATCH 2/4] minor fixes --- benchmark/single-source/SetTests.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/benchmark/single-source/SetTests.swift b/benchmark/single-source/SetTests.swift index 5f5bc6ccf902a..52b29873105ac 100644 --- a/benchmark/single-source/SetTests.swift +++ b/benchmark/single-source/SetTests.swift @@ -155,9 +155,9 @@ public let SetTests = [ setUpFunction: { blackHole([setOAB, arrayOCD]) }), BenchmarkInfo( name: "Set.isSubset.Seq.Int25", - runFunction: { n in run_SetIsSubsetSeqInt(setB, arrayAB, true, 50 * n) }, + runFunction: { n in run_SetIsSubsetSeqInt(setB, arrayBC, true, 50 * n) }, tags: [.validation, .api, .Set], - setUpFunction: { blackHole([setB, arrayAB]) }), + setUpFunction: { blackHole([setB, arrayBC]) }), BenchmarkInfo( name: "Set.isSubset.Seq.Box25", runFunction: { n in run_SetIsSubsetSeqBox(setOB, arrayOAB, true, 50 * n) }, @@ -237,9 +237,9 @@ public let SetTests = [ setUpFunction: { blackHole([setOAB, arrayOCD]) }), BenchmarkInfo( name: "Set.isStrictSubset.Seq.Int25", - runFunction: { n in run_SetIsStrictSubsetSeqInt(setB, arrayAB, true, 50 * n) }, + runFunction: { n in run_SetIsStrictSubsetSeqInt(setB, arrayBC, true, 50 * n) }, tags: [.validation, .api, .Set], - setUpFunction: { blackHole([setB, arrayAB]) }), + setUpFunction: { blackHole([setB, arrayBC]) }), BenchmarkInfo( name: "Set.isStrictSubset.Seq.Box25", runFunction: { n in run_SetIsStrictSubsetSeqBox(setOB, arrayOAB, true, 50 * n) }, @@ -278,9 +278,9 @@ public let SetTests = [ setUpFunction: { blackHole([setOCD, arrayOAB]) }), BenchmarkInfo( name: "Set.isSuperset.Seq.Int25", - runFunction: { n in run_SetIsSupersetSeqInt(setAB, arrayB, true, 50 * n) }, + runFunction: { n in run_SetIsSupersetSeqInt(setB, arrayBC, false, 50 * n) }, tags: [.validation, .api, .Set], - setUpFunction: { blackHole([setAB, arrayB]) }), + setUpFunction: { blackHole([setB, arrayBC]) }), BenchmarkInfo( name: "Set.isSuperset.Seq.Box25", runFunction: { n in run_SetIsSupersetSeqBox(setOAB, arrayOB, true, 50 * n) }, @@ -319,9 +319,9 @@ public let SetTests = [ setUpFunction: { blackHole([setOCD, arrayOAB]) }), BenchmarkInfo( name: "Set.isStrictSuperset.Seq.Int25", - runFunction: { n in run_SetIsStrictSupersetSeqInt(setAB, arrayB, true, 50 * n) }, + runFunction: { n in run_SetIsStrictSupersetSeqInt(setB, arrayBC, false, 50 * n) }, tags: [.validation, .api, .Set], - setUpFunction: { blackHole([setAB, arrayB]) }), + setUpFunction: { blackHole([setB, arrayBC]) }), BenchmarkInfo( name: "Set.isStrictSuperset.Seq.Box25", runFunction: { n in run_SetIsStrictSupersetSeqBox(setOAB, arrayOB, true, 50 * n) }, From a75f2d7536ed0ab9309ceb152628726d128d4b02 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 10 May 2019 22:54:01 +0200 Subject: [PATCH 3/4] [benchmark] Set.Seq showcase optimized early exits --- benchmark/single-source/SetTests.swift | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/benchmark/single-source/SetTests.swift b/benchmark/single-source/SetTests.swift index 52b29873105ac..a7c8d500ed20e 100644 --- a/benchmark/single-source/SetTests.swift +++ b/benchmark/single-source/SetTests.swift @@ -160,14 +160,14 @@ public let SetTests = [ setUpFunction: { blackHole([setB, arrayBC]) }), BenchmarkInfo( name: "Set.isSubset.Seq.Box25", - runFunction: { n in run_SetIsSubsetSeqBox(setOB, arrayOAB, true, 50 * n) }, + runFunction: { n in run_SetIsSubsetSeqBox(setOB, arrayOBC, true, 50 * n) }, tags: [.validation, .api, .Set], - setUpFunction: { blackHole([setOB, arrayOAB]) }), + setUpFunction: { blackHole([setOB, arrayOBC]) }), BenchmarkInfo( name: "Set.isSubset.Seq.Int50", - runFunction: { n in run_SetIsSubsetSeqInt(setY, arrayXY, true, 50 * n) }, + runFunction: { n in run_SetIsSubsetSeqInt(setY, arrayYZ, true, 50 * n) }, tags: [.validation, .api, .Set], - setUpFunction: { blackHole([setY, arrayXY]) }), + setUpFunction: { blackHole([setY, arrayYZ]) }), BenchmarkInfo( name: "Set.isSubset.Seq.Int100", runFunction: { n in run_SetIsSubsetSeqInt(setP, arrayP, true, 50 * n) }, @@ -242,14 +242,14 @@ public let SetTests = [ setUpFunction: { blackHole([setB, arrayBC]) }), BenchmarkInfo( name: "Set.isStrictSubset.Seq.Box25", - runFunction: { n in run_SetIsStrictSubsetSeqBox(setOB, arrayOAB, true, 50 * n) }, + runFunction: { n in run_SetIsStrictSubsetSeqBox(setOB, arrayOBC, true, 50 * n) }, tags: [.validation, .api, .Set], - setUpFunction: { blackHole([setOB, arrayOAB]) }), + setUpFunction: { blackHole([setOB, arrayOBC]) }), BenchmarkInfo( name: "Set.isStrictSubset.Seq.Int50", - runFunction: { n in run_SetIsStrictSubsetSeqInt(setY, arrayXY, true, 50 * n) }, + runFunction: { n in run_SetIsStrictSubsetSeqInt(setY, arrayYZ, true, 50 * n) }, tags: [.validation, .api, .Set], - setUpFunction: { blackHole([setY, arrayXY]) }), + setUpFunction: { blackHole([setY, arrayYZ]) }), BenchmarkInfo( name: "Set.isStrictSubset.Seq.Int100", runFunction: { n in run_SetIsStrictSubsetSeqInt(setP, arrayP, false, 50 * n) }, @@ -283,14 +283,14 @@ public let SetTests = [ setUpFunction: { blackHole([setB, arrayBC]) }), BenchmarkInfo( name: "Set.isSuperset.Seq.Box25", - runFunction: { n in run_SetIsSupersetSeqBox(setOAB, arrayOB, true, 50 * n) }, + runFunction: { n in run_SetIsSupersetSeqBox(setOB, arrayOBC, false, 50 * n) }, tags: [.validation, .api, .Set], - setUpFunction: { blackHole([setOAB, arrayOB]) }), + setUpFunction: { blackHole([setOB, arrayOBC]) }), BenchmarkInfo( name: "Set.isSuperset.Seq.Int50", - runFunction: { n in run_SetIsSupersetSeqInt(setXY, arrayY, true, 50 * n) }, + runFunction: { n in run_SetIsSupersetSeqInt(setY, arrayYZ, false, 50 * n) }, tags: [.validation, .api, .Set], - setUpFunction: { blackHole([setXY, arrayY]) }), + setUpFunction: { blackHole([setY, arrayYZ]) }), BenchmarkInfo( name: "Set.isSuperset.Seq.Int100", runFunction: { n in run_SetIsSupersetSeqInt(setP, arrayP, true, 50 * n) }, @@ -324,14 +324,14 @@ public let SetTests = [ setUpFunction: { blackHole([setB, arrayBC]) }), BenchmarkInfo( name: "Set.isStrictSuperset.Seq.Box25", - runFunction: { n in run_SetIsStrictSupersetSeqBox(setOAB, arrayOB, true, 50 * n) }, + runFunction: { n in run_SetIsStrictSupersetSeqBox(setOB, arrayOBC, false, 50 * n) }, tags: [.validation, .api, .Set], - setUpFunction: { blackHole([setOAB, arrayOB]) }), + setUpFunction: { blackHole([setOB, arrayOBC]) }), BenchmarkInfo( name: "Set.isStrictSuperset.Seq.Int50", - runFunction: { n in run_SetIsStrictSupersetSeqInt(setXY, arrayY, true, 50 * n) }, + runFunction: { n in run_SetIsStrictSupersetSeqInt(setY, arrayYZ, false, 50 * n) }, tags: [.validation, .api, .Set], - setUpFunction: { blackHole([setXY, arrayY]) }), + setUpFunction: { blackHole([setY, arrayYZ]) }), BenchmarkInfo( name: "Set.isStrictSuperset.Seq.Int100", runFunction: { n in run_SetIsStrictSupersetSeqInt(setP, arrayP, false, 50 * n) }, From 07f373d9658214e6b66b8c1fdc483f9835a57714 Mon Sep 17 00:00:00 2001 From: Pavol Vaskovic Date: Fri, 10 May 2019 23:54:31 +0200 Subject: [PATCH 4/4] [benchmark] Set.subtracting.Seq increased workload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The workload multipliers need to be increased in order to accommodate the pending improvements from `lorentey:set-on-fire`, so that these benchmark don't drop to under 20 μs runtimes when those optimizations kick in. These multiplier will differ from those used on Set.subtracting.Set by a factor of 5. --- benchmark/single-source/SetTests.swift | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/benchmark/single-source/SetTests.swift b/benchmark/single-source/SetTests.swift index a7c8d500ed20e..5d644aa392994 100644 --- a/benchmark/single-source/SetTests.swift +++ b/benchmark/single-source/SetTests.swift @@ -617,52 +617,52 @@ public let SetTests = [ BenchmarkInfo( name: "Set.subtracting.Seq.Empty.Int", - runFunction: { n in run_SetSubtractingSeqInt(setE, arrayAB, 0, 1000 * n) }, + runFunction: { n in run_SetSubtractingSeqInt(setE, arrayAB, 0, 5000 * n) }, tags: [.validation, .api, .Set], setUpFunction: { blackHole([setE, arrayAB]) }), BenchmarkInfo( name: "Set.subtracting.Seq.Int.Empty", - runFunction: { n in run_SetSubtractingSeqInt(setAB, arrayE, countAB, 1000 * n) }, + runFunction: { n in run_SetSubtractingSeqInt(setAB, arrayE, countAB, 5000 * n) }, tags: [.validation, .api, .Set], setUpFunction: { blackHole([setAB, arrayE]) }), BenchmarkInfo( name: "Set.subtracting.Seq.Empty.Box", - runFunction: { n in run_SetSubtractingSeqBox(setOE, arrayOAB, 0, 1000 * n) }, + runFunction: { n in run_SetSubtractingSeqBox(setOE, arrayOAB, 0, 5000 * n) }, tags: [.validation, .api, .Set], setUpFunction: { blackHole([setOE, arrayOAB]) }), BenchmarkInfo( name: "Set.subtracting.Seq.Box.Empty", - runFunction: { n in run_SetSubtractingSeqBox(setOAB, arrayOE, countAB, 1000 * n) }, + runFunction: { n in run_SetSubtractingSeqBox(setOAB, arrayOE, countAB, 5000 * n) }, tags: [.validation, .api, .Set], setUpFunction: { blackHole([setOAB, arrayOE]) }), BenchmarkInfo( name: "Set.subtracting.Seq.Int0", - runFunction: { n in run_SetSubtractingSeqInt(setAB, arrayCD, countAB, 10 * n) }, + runFunction: { n in run_SetSubtractingSeqInt(setAB, arrayCD, countAB, 50 * n) }, tags: [.validation, .api, .Set], setUpFunction: { blackHole([setAB, arrayCD]) }), BenchmarkInfo( name: "Set.subtracting.Seq.Box0", - runFunction: { n in run_SetSubtractingSeqBox(setOAB, arrayOCD, countAB, 10 * n) }, + runFunction: { n in run_SetSubtractingSeqBox(setOAB, arrayOCD, countAB, 50 * n) }, tags: [.validation, .api, .Set], setUpFunction: { blackHole([setOAB, arrayOCD]) }), BenchmarkInfo( name: "Set.subtracting.Seq.Int25", - runFunction: { n in run_SetSubtractingSeqInt(setAB, arrayBC, countA, 10 * n) }, + runFunction: { n in run_SetSubtractingSeqInt(setAB, arrayBC, countA, 50 * n) }, tags: [.validation, .api, .Set], setUpFunction: { blackHole([setAB, arrayBC]) }), BenchmarkInfo( name: "Set.subtracting.Seq.Box25", - runFunction: { n in run_SetSubtractingSeqBox(setOAB, arrayOBC, countA, 10 * n) }, + runFunction: { n in run_SetSubtractingSeqBox(setOAB, arrayOBC, countA, 50 * n) }, tags: [.validation, .api, .Set], setUpFunction: { blackHole([setOAB, arrayOBC]) }), BenchmarkInfo( name: "Set.subtracting.Seq.Int50", - runFunction: { n in run_SetSubtractingSeqInt(setXY, arrayYZ, half, 10 * n) }, + runFunction: { n in run_SetSubtractingSeqInt(setXY, arrayYZ, half, 50 * n) }, tags: [.validation, .api, .Set], setUpFunction: { blackHole([setXY, arrayYZ]) }), BenchmarkInfo( name: "Set.subtracting.Seq.Int100", - runFunction: { n in run_SetSubtractingSeqInt(setP, arrayP, 0, 10 * n) }, + runFunction: { n in run_SetSubtractingSeqInt(setP, arrayP, 0, 50 * n) }, tags: [.validation, .api, .Set], setUpFunction: { blackHole([setP, arrayP]) }),