Skip to content

Commit

Permalink
Swift 3 updates for the benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
wokalski committed Nov 21, 2016
1 parent 6e217b8 commit 79ca18e
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 48 deletions.
79 changes: 73 additions & 6 deletions PerfTests/Benchmark/Benchmark.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
objects = {

/* Begin PBXBuildFile section */
C92178C41CD01050004642C7 /* Diff.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C92178C21CD01050004642C7 /* Diff.framework */; };
C92178C51CD01050004642C7 /* Dwifft.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C92178C31CD01050004642C7 /* Dwifft.framework */; };
C92178C91CD01085004642C7 /* Diff.framework in Copy Files */ = {isa = PBXBuildFile; fileRef = C92178C21CD01050004642C7 /* Diff.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
C92178CA1CD01085004642C7 /* Dwifft.framework in Copy Files */ = {isa = PBXBuildFile; fileRef = C92178C31CD01050004642C7 /* Dwifft.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
C9278AA51DE309D3009CE846 /* Diff.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9278AA01DE309B5009CE846 /* Diff.framework */; };
C9278AA61DE30B81009CE846 /* Diff.framework in Copy Files */ = {isa = PBXBuildFile; fileRef = C9278AA01DE309B5009CE846 /* Diff.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
C93B984A1CD114D200047B30 /* Diff-new.swift in Copy Files */ = {isa = PBXBuildFile; fileRef = C93B98461CD114C700047B30 /* Diff-new.swift */; };
C93B984B1CD114D200047B30 /* Diff-old.swift in Copy Files */ = {isa = PBXBuildFile; fileRef = C93B98471CD114C700047B30 /* Diff-old.swift */; };
C98888F41CD0A489000DA46C /* PerformanceTestUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = C98888F31CD0A489000DA46C /* PerformanceTestUtils.swift */; };
Expand All @@ -22,15 +22,39 @@
C9EE876D1CCFD8AD006BD90E /* Dwifft.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9EE876C1CCFD8AD006BD90E /* Dwifft.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
C9278A9F1DE309B5009CE846 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = C9278A991DE309B5009CE846 /* Diff.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = C9EE87161CCFCA83006BD90E;
remoteInfo = "Diff-iOS";
};
C9278AA11DE309B5009CE846 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = C9278A991DE309B5009CE846 /* Diff.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = C9EE872D1CCFCB33006BD90E;
remoteInfo = "Diff-Mac";
};
C9278AA31DE309B5009CE846 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = C9278A991DE309B5009CE846 /* Diff.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = C9838FF11D29571000691BE8;
remoteInfo = DiffTests;
};
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
C92178C81CD01079004642C7 /* Copy Files */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
C92178C91CD01085004642C7 /* Diff.framework in Copy Files */,
C92178CA1CD01085004642C7 /* Dwifft.framework in Copy Files */,
C9278AA61DE30B81009CE846 /* Diff.framework in Copy Files */,
);
name = "Copy Files";
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -50,8 +74,8 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
C92178C21CD01050004642C7 /* Diff.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Diff.framework; path = Carthage/Build/iOS/Diff.framework; sourceTree = SOURCE_ROOT; };
C92178C31CD01050004642C7 /* Dwifft.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Dwifft.framework; path = Carthage/Build/iOS/Dwifft.framework; sourceTree = SOURCE_ROOT; };
C9278A991DE309B5009CE846 /* Diff.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Diff.xcodeproj; path = ../../../Diff.xcodeproj; sourceTree = "<group>"; };
C93B98461CD114C700047B30 /* Diff-new.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Diff-new.swift"; path = "../../Utils/Resources/Diff-new.swift"; sourceTree = "<group>"; };
C93B98471CD114C700047B30 /* Diff-old.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Diff-old.swift"; path = "../../Utils/Resources/Diff-old.swift"; sourceTree = "<group>"; };
C98888F31CD0A489000DA46C /* PerformanceTestUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PerformanceTestUtils.swift; path = ../../Utils/PerformanceTestUtils.swift; sourceTree = "<group>"; };
Expand All @@ -71,7 +95,7 @@
buildActionMask = 2147483647;
files = (
C92178C51CD01050004642C7 /* Dwifft.framework in Frameworks */,
C92178C41CD01050004642C7 /* Diff.framework in Frameworks */,
C9278AA51DE309D3009CE846 /* Diff.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -92,12 +116,22 @@
C92178C11CD01034004642C7 /* Frameworks */ = {
isa = PBXGroup;
children = (
C92178C21CD01050004642C7 /* Diff.framework */,
C9278A991DE309B5009CE846 /* Diff.xcodeproj */,
C92178C31CD01050004642C7 /* Dwifft.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
C9278A9A1DE309B5009CE846 /* Products */ = {
isa = PBXGroup;
children = (
C9278AA01DE309B5009CE846 /* Diff.framework */,
C9278AA21DE309B5009CE846 /* Diff.framework */,
C9278AA41DE309B5009CE846 /* DiffTests.xctest */,
);
name = Products;
sourceTree = "<group>";
};
C9EE86E11CCFBAFD006BD90E = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -172,6 +206,7 @@
C9EE86E91CCFBAFD006BD90E = {
CreatedOnToolsVersion = 7.3;
DevelopmentTeam = 25UJHK4C3S;
LastSwiftMigration = 0800;
};
};
};
Expand All @@ -186,13 +221,43 @@
mainGroup = C9EE86E11CCFBAFD006BD90E;
productRefGroup = C9EE86EB1CCFBAFD006BD90E /* Products */;
projectDirPath = "";
projectReferences = (
{
ProductGroup = C9278A9A1DE309B5009CE846 /* Products */;
ProjectRef = C9278A991DE309B5009CE846 /* Diff.xcodeproj */;
},
);
projectRoot = "";
targets = (
C9EE86E91CCFBAFD006BD90E /* Benchmark */,
);
};
/* End PBXProject section */

/* Begin PBXReferenceProxy section */
C9278AA01DE309B5009CE846 /* Diff.framework */ = {
isa = PBXReferenceProxy;
fileType = wrapper.framework;
path = Diff.framework;
remoteRef = C9278A9F1DE309B5009CE846 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
C9278AA21DE309B5009CE846 /* Diff.framework */ = {
isa = PBXReferenceProxy;
fileType = wrapper.framework;
path = Diff.framework;
remoteRef = C9278AA11DE309B5009CE846 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
C9278AA41DE309B5009CE846 /* DiffTests.xctest */ = {
isa = PBXReferenceProxy;
fileType = wrapper.cfbundle;
path = DiffTests.xctest;
remoteRef = C9278AA31DE309B5009CE846 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */

/* Begin PBXResourcesBuildPhase section */
C9EE86E81CCFBAFD006BD90E /* Resources */ = {
isa = PBXResourcesBuildPhase;
Expand Down Expand Up @@ -336,6 +401,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.wczekalski.Benchmark;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -352,6 +418,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.wczekalski.Benchmark;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions PerfTests/Benchmark/Benchmark/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
13 changes: 3 additions & 10 deletions PerfTests/Benchmark/Benchmark/Dwifft.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
//
// Dwifft.swift
// Benchmark
//
// Created by Wojciech Czekalski on 26.04.2016.
// Copyright © 2016 wczekalski. All rights reserved.
//

import Dwifft

func performDwifft(a: [Character], b: [Character]) {
func performDwifft(_ a: [Character], b: [Character]) {
_ = dwifft(a, b: b)
}

private func dwifft(a: [Character], b: [Character]) -> Dwifft.Diff<Character> {
private func dwifft(_ a: [Character], b: [Character]) -> Dwifft.Diff<Character> {
return a.diff(b)
}
}
8 changes: 4 additions & 4 deletions PerfTests/Benchmark/Benchmark/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

class ViewController: UIViewController {

override func viewDidAppear(animated: Bool) {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

let from = pathForFile(fileName: "Diff-old")
Expand All @@ -21,14 +21,14 @@ class ViewController: UIViewController {

print("Both libraries are compiled with -O -whole-module-optimization\n")
print(" | Diff.swift | Dwifft ")
print("-------------------------------")
print("---------|------------|--------")
print(" same | \(diff.same) | \(dwifft.same)")
print(" created | \(diff.created) | \(dwifft.created)")
print(" deleted | \(diff.deleted) | \(dwifft.deleted)")
print(" diff | \(diff.changed) | \(dwifft.changed)")
}
}

func pathForFile(fileName fileName: String) -> String{
return NSBundle.mainBundle().pathForResource(fileName, ofType: "swift")!
func pathForFile(fileName: String) -> String{
return Bundle.main.path(forResource: fileName, ofType: "swift")!
}
1 change: 0 additions & 1 deletion PerfTests/Benchmark/Cartfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
github "jflinter/Dwifft"
github "wokalski/Diff.swift" "master"

8 changes: 4 additions & 4 deletions PerfTests/PerfTests/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
This is a test file
*/

let resourcesPath = proccessPath().stringByAppendingString("/Resources/")
let from = resourcesPath.stringByAppendingString("Diff-old.swift")
let to = resourcesPath.stringByAppendingString("Diff-new.swift")
let diff = performDiff(from, toFilePath: to, repeatCount: 5, diffFunc: diffSwift)
let resourcesPath = proccessPath().appending("/Resources/")
let from = resourcesPath.appending("Diff-old.swift")
let to = resourcesPath.appending("Diff-new.swift")
let diff = performDiff(fromFilePath: from, toFilePath: to, repeatCount: 5, diffFunc: diffSwift)

print(" | Diff.swift |")
print("-----------------------")
Expand Down
34 changes: 17 additions & 17 deletions PerfTests/Utils/PerformanceTestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import Foundation
import Diff

func performDiff(fromFilePath: String, toFilePath: String, repeatCount: Int = 10, diffFunc: ([Character], [Character]) -> Void) -> (created: String, deleted: String, same: String, changed: String) {
let old = file(path: fromFilePath)
let new = file(path: toFilePath)
func performDiff(_ fromFilePath: String, toFilePath: String, repeatCount: Int = 10, diffFunc: @escaping ([Character], [Character]) -> Void) -> (created: String, deleted: String, same: String, changed: String) {
let old = file(fromFilePath)
let new = file(toFilePath)
let compare: ([Character], [Character]) -> String = { a, b in
var time: CFTimeInterval = 0
for _ in 0..<repeatCount {
Expand All @@ -28,44 +28,44 @@ func performDiff(fromFilePath: String, toFilePath: String, repeatCount: Int = 10
}

func currentDirectoryPath() -> String {
let buffer: UnsafeMutablePointer<Int8> = UnsafeMutablePointer.alloc(Int(PATH_MAX))
let buffer: UnsafeMutablePointer<Int8> = UnsafeMutablePointer.allocate(capacity: Int(PATH_MAX))
getcwd(buffer, Int(PATH_MAX))
let string = String.fromCString(buffer)
buffer.dealloc(Int(PATH_MAX))
return string!
let string = String(cString: buffer)
buffer.deallocate(capacity: Int(PATH_MAX))
return string
}

func measure(f: () -> Void) -> CFTimeInterval {
func measure(_ f: () -> Void) -> CFTimeInterval {
let time = CFAbsoluteTimeGetCurrent()
f()
return CFAbsoluteTimeGetCurrent() - time
}

func file(path path: String) -> [Character] {
func file(_ path: String) -> [Character] {
return try! Array(String(contentsOfFile: path).characters)

}

func diffSwift(a: [Character], b: [Character]) {
func diffSwift(_ a: [Character], b: [Character]) {
_ = _diffSwift(a, b: b)
}

private func _diffSwift(a: [Character], b: [Character]) -> Diff {
private func _diffSwift(_ a: [Character], b: [Character]) -> Diff {
return a.diff(b)
}

func launchPath() -> String {
let path = Process.arguments.first!
let dotIndex = path.startIndex.successor()
var lastSlashIndex = path.endIndex.predecessor()
let path = CommandLine.arguments.first!
let dotIndex = path.index(after: path.startIndex)
var lastSlashIndex = path.index(before: path.endIndex)
let c: Character = "/"
while path.characters[lastSlashIndex] != c {
lastSlashIndex = lastSlashIndex.predecessor()
lastSlashIndex = path.index(before: lastSlashIndex)
}
return path.substringToIndex(lastSlashIndex).substringFromIndex(dotIndex)
return path.substring(to: lastSlashIndex).substring(from: dotIndex)
}

func proccessPath() -> String {
return currentDirectoryPath().stringByAppendingString(launchPath())
return currentDirectoryPath().appending(launchPath())
}

0 comments on commit 79ca18e

Please sign in to comment.