Skip to content

Commit

Permalink
Merge pull request #82 from ra1028/ordered-collection-diffing
Browse files Browse the repository at this point in the history
Ordered collection diffing benchmark
  • Loading branch information
ra1028 committed Oct 20, 2019
2 parents 757b69e + 44b9f9e commit 1fcff13
Show file tree
Hide file tree
Showing 35 changed files with 613 additions and 287 deletions.
13 changes: 10 additions & 3 deletions Benchmark/Benchmark.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 51;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -76,9 +76,9 @@
6BAE81A4227B288F0060866E /* Sources */ = {
isa = PBXGroup;
children = (
6BAEA3D2227E121C0026F81E /* Info.plist */,
6BAEA367227B30C00026F81E /* main.swift */,
6BAEA3D4227E134B0026F81E /* BenchmarkTools.swift */,
6BAEA3D2227E121C0026F81E /* Info.plist */,
);
path = Sources;
sourceTree = "<group>";
Expand Down Expand Up @@ -349,13 +349,15 @@
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Sources/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.ryo.Benchmark;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_ENFORCE_EXCLUSIVE_ACCESS = on;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -368,15 +370,20 @@
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
GCC_OPTIMIZATION_LEVEL = s;
GCC_OPTIMIZATION_LEVEL = fast;
INFOPLIST_FILE = Sources/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.ryo.Benchmark;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_ENFORCE_EXCLUSIVE_ACCESS = on;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -38,8 +36,8 @@
ReferencedContainer = "container:Benchmark.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Release"
Expand All @@ -61,8 +59,6 @@
ReferencedContainer = "container:Benchmark.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http:https://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
<dict>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Benchmark/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source "https://rubygems.org"

gem 'cocoapods', '1.7.0.rc.1'
gem 'cocoapods', '1.8.4'
33 changes: 20 additions & 13 deletions Benchmark/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.0)
CFPropertyList (3.0.1)
activesupport (4.2.11.1)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
algoliasearch (1.27.1)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
claide (1.0.2)
cocoapods (1.7.0.rc.1)
claide (1.0.3)
cocoapods (1.8.4)
activesupport (>= 4.0.2, < 5)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.7.0.rc.1)
cocoapods-core (= 1.8.4)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.2.2, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-stats (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.3.1, < 2.0)
cocoapods-trunk (>= 1.4.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (>= 2.2.0, < 3.0)
fourflusher (>= 2.3.0, < 3.0)
gh_inspector (~> 1.0)
molinillo (~> 0.6.6)
nap (~> 1.0)
ruby-macho (~> 1.4)
xcodeproj (>= 1.8.2, < 2.0)
cocoapods-core (1.7.0.rc.1)
xcodeproj (>= 1.11.1, < 2.0)
cocoapods-core (1.8.4)
activesupport (>= 4.0.2, < 6)
algoliasearch (~> 1.0)
concurrent-ruby (~> 1.1)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
cocoapods-deintegrate (1.0.4)
Expand All @@ -38,19 +43,21 @@ GEM
nap
cocoapods-search (1.0.0)
cocoapods-stats (1.1.0)
cocoapods-trunk (1.3.1)
cocoapods-trunk (1.4.1)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.1.0)
colored2 (3.1.2)
concurrent-ruby (1.1.5)
escape (0.0.4)
fourflusher (2.2.0)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
minitest (5.11.3)
json (2.2.0)
minitest (5.12.2)
molinillo (0.6.6)
nanaimo (0.2.6)
nap (1.1.0)
Expand All @@ -59,7 +66,7 @@ GEM
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
xcodeproj (1.9.0)
xcodeproj (1.13.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
Expand All @@ -70,7 +77,7 @@ PLATFORMS
ruby

DEPENDENCIES
cocoapods (= 1.7.0.rc.1)
cocoapods (= 1.8.4)

BUNDLED WITH
2.0.1
6 changes: 3 additions & 3 deletions Benchmark/Podfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
platform :ios, '12.2'
platform :ios, '13.0'

use_frameworks!
inhibit_all_warnings!
Expand All @@ -10,7 +10,7 @@ target 'Benchmark' do
pod 'Differentiator', '4.0.1'
pod 'FlexibleDiff', '0.0.8'
pod 'IGListKit', '3.4.0'
pod 'DeepDiff', '2.0.1'
pod 'Differ', '1.4.1'
pod 'DeepDiff', '2.2.0'
pod 'Differ', '1.4.3'
pod 'Dwifft', '0.9'
end
30 changes: 15 additions & 15 deletions Benchmark/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
PODS:
- DeepDiff (2.0.1)
- Differ (1.4.1)
- DifferenceKit (1.1.2):
- DifferenceKit/Core (= 1.1.2)
- DifferenceKit/UIKitExtension (= 1.1.2)
- DifferenceKit/Core (1.1.2)
- DifferenceKit/UIKitExtension (1.1.2):
- DeepDiff (2.2.0)
- Differ (1.4.3)
- DifferenceKit (1.1.3):
- DifferenceKit/Core (= 1.1.3)
- DifferenceKit/UIKitExtension (= 1.1.3)
- DifferenceKit/Core (1.1.3)
- DifferenceKit/UIKitExtension (1.1.3):
- DifferenceKit/Core
- Differentiator (4.0.1)
- Dwifft (0.9)
Expand All @@ -17,16 +17,16 @@ PODS:
- IGListKit/Diffing (3.4.0)

DEPENDENCIES:
- DeepDiff (= 2.0.1)
- Differ (= 1.4.1)
- DeepDiff (= 2.2.0)
- Differ (= 1.4.3)
- DifferenceKit (from `../`)
- Differentiator (= 4.0.1)
- Dwifft (= 0.9)
- FlexibleDiff (= 0.0.8)
- IGListKit (= 3.4.0)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
https://github.com/CocoaPods/Specs.git:
- DeepDiff
- Differ
- Differentiator
Expand All @@ -39,14 +39,14 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
DeepDiff: 1944bb2c841ab238a66b31de1faa7627f3ca84bd
Differ: ca4350872e32a1aeedf3d9e2d9e47127833bfa9c
DifferenceKit: 3a1cff9ac9a9cdf2a3f205671067797e83c3f066
DeepDiff: e329bc46dd14ca788d8ec08d34420799ba1d77f2
Differ: 6c7477d6187e8c36d02ec342a3c321061b85a0ea
DifferenceKit: e2c432b59833a7bae2a5cc3175950edbbbab40da
Differentiator: 886080237d9f87f322641dedbc5be257061b0602
Dwifft: 42912068ed2a8146077d1a1404df18625bd086e1
FlexibleDiff: 4f487778bd152088a9528a0a9be06eba7952bb00
IGListKit: 7a5d788e9fb746bcd402baa8e8b24bc3bd2a5a07

PODFILE CHECKSUM: 23af01fe899c46fcc51f3bfb5ea8d445f4c1d895
PODFILE CHECKSUM: 2a95de47f8e05bd0b4653734f981d57cbc4395fb

COCOAPODS: 1.7.0.rc.1
COCOAPODS: 1.8.4
31 changes: 26 additions & 5 deletions Benchmark/Sources/BenchmarkTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ struct Benchmark {
let start = CFAbsoluteTimeGetCurrent()
action()
let end = CFAbsoluteTimeGetCurrent()

return end - start
}
}
Expand All @@ -76,6 +75,7 @@ struct BenchmarkRunner {
}

func run(with data: BenchmarkData) {
let benchmarks = self.benchmarks
let sourceCount = String.localizedStringWithFormat("%d", data.source.count)
let deleteCount = String.localizedStringWithFormat("%d", data.deleteRange.count)
let insertCount = String.localizedStringWithFormat("%d", data.insertRange.count)
Expand All @@ -97,12 +97,33 @@ struct BenchmarkRunner {
|\(leftAlignSpacer)|\(rightAlignSpacer)|
""")

for benchmark in benchmarks {
let paddingName = benchmark.name.padding(toLength: maxLength, withPad: " ", startingAt: 0)
print("|\(paddingName)|", terminator: "")
var results = ContiguousArray<CFAbsoluteTime?>(repeating: nil, count: benchmarks.count)
let group = DispatchGroup()
let queue = DispatchQueue(label: "Measure benchmark queue", attributes: .concurrent)

for (offset, benchmark) in benchmarks.enumerated() {
group.enter()

queue.async(group: group) {
let first = benchmark.measure(with: data)
let second = benchmark.measure(with: data)
let third = benchmark.measure(with: data)
results[offset] = min(first, second, third)
group.leave()
}
}

let result = benchmark.measure(with: data)
group.wait()

for (offset, benchmark) in benchmarks.enumerated() {
guard let result = results[offset] else {
fatalError("Measuring was not works correctly.")
}

let paddingName = benchmark.name.padding(toLength: maxLength, withPad: " ", startingAt: 0)
let paddingTime = String(format: "`%.4f`", result).padding(toLength: maxLength, withPad: " ", startingAt: 0)

print("|\(paddingName)|", terminator: "")
print("\(paddingTime)|")
}

Expand Down
4 changes: 4 additions & 0 deletions Benchmark/Sources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIcons</key>
<dict/>
<key>CFBundleIcons~ipad</key>
<dict/>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
Expand Down
5 changes: 5 additions & 0 deletions Benchmark/Sources/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ let runner = BenchmarkRunner(
return {
_ = Dwifft.diff(data.source, data.target)
}
},
Benchmark(name: "Swift.CollectionDifference") { data in
return {
_ = data.target.difference(from: data.source).inferringMoves()
}
}
)

Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "https://rubygems.org"

gem 'cocoapods', '1.7.2'
gem 'jazzy', '0.9.4'
gem 'cocoapods', '1.8.4'
gem 'jazzy', '0.11.2'
Loading

0 comments on commit 1fcff13

Please sign in to comment.