Skip to content

Commit

Permalink
Merge pull request #48 from dn-m/linux
Browse files Browse the repository at this point in the history
Add support for Linux
  • Loading branch information
jsbean authored Aug 13, 2018
2 parents a851bc3 + 930eaef commit d48417c
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 14 deletions.
13 changes: 9 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
os:
- osx
- linux
language: generic
sudo: required
dist: trusty
osx_image: xcode9
install:
- wget https://swift.org/builds/swift-4.2-branch/xcode/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-05-30-a/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-05-30-a-osx.pkg
- sudo installer -pkg swift-4.2-DEVELOPMENT-SNAPSHOT-2018-05-30-a-osx.pkg -target /
- export PATH="/Library/Developer/Toolchains/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-05-30-a.xctoolchain/usr/bin:$PATH"
- eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
env:
- SWIFT_VERSION=DEVELOPMENT-SNAPSHOT-2018-05-30-a
script:
- swift build
- swift test
after_success:
- git clone https://github.com/dn-m/Documentarian && cd Documentarian
- swift build -c release -Xswiftc -static-stdlib
- cd ../
- Documentarian/.build/Release/Documentarian
16 changes: 13 additions & 3 deletions Sources/PerformanceTesting/Benchmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
// Created by James Bean on 8/11/17.
//

import Foundation
#if os(Linux)
import Glibc
#else
import Darwin.C
#endif

import Dispatch

/// Collection of `TestPoint` values.
public struct Benchmark {
Expand Down Expand Up @@ -108,12 +114,16 @@ extension Benchmark: CustomStringConvertible {

/// - Returns: The amount of time that it takes to perform the given `operation`.
private func measure (operation: () -> Void) -> Double {
let start = CFAbsoluteTimeGetCurrent()
let start = now()
operation()
let finish = CFAbsoluteTimeGetCurrent()
let finish = now()
return finish - start
}

private func now() -> Double {
return Double(DispatchTime.now().uptimeNanoseconds) / 1_000_000_000
}

extension Array where Element == Double {

public var sum: Double {
Expand Down
6 changes: 5 additions & 1 deletion Sources/PerformanceTesting/Complexity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// Created by James Bean on 8/10/17.
//

import Darwin
#if os(Linux)
import Glibc
#else
import Darwin.C
#endif

/// Classes of complexity (big-oh style).
public enum Complexity {
Expand Down
6 changes: 5 additions & 1 deletion Sources/PerformanceTesting/DataSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// Created by James Bean on 8/10/17.
//

import Darwin
#if os(Linux)
import Glibc
#else
import Darwin.C
#endif

/// Collection of (x,y) data points.
struct DataSet {
Expand Down
6 changes: 5 additions & 1 deletion Sources/PerformanceTesting/Scale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// Created by James Bean on 8/10/17.
//

import Darwin
#if os(Linux)
import Glibc
#else
import Darwin.C
#endif

/// Ranges of values to use for testPoints (values of `n` in `O(f(n))`).
public struct Scale {
Expand Down
10 changes: 6 additions & 4 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import XCTest
@testable import PerformanceTestingTests

XCTMain([
testCase(PerformanceTestingTests.allTests),
])
import PerformanceTestingTests

var tests = [XCTestCaseEntry]()
tests += PerformanceTestingTests.__allTests()

XCTMain(tests)
104 changes: 104 additions & 0 deletions Tests/PerformanceTestingTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import XCTest

extension AlgorithmComplexityTests {
static let __allTests = [
("testExponential_RecursiveFibonacci", testExponential_RecursiveFibonacci),
("testQuadratic_MatrixAdd", testQuadratic_MatrixAdd),
("testQuadratic_MatrixFill", testQuadratic_MatrixFill),
("testQuadratic_MatrixMultiply", testQuadratic_MatrixMultiply),
("testSquareRoot_Primality", testSquareRoot_Primality),
]
}

extension ArrayTests {
static let __allTests = [
("testAppend", testAppend),
("testAppendAmortized", testAppendAmortized),
("testCount", testCount),
("testFirst", testFirst),
("testInsert", testInsert),
("testIsEmpty", testIsEmpty),
("testLast", testLast),
("testPartition", testPartition),
("testRemove", testRemove),
("testSort", testSort),
("testSubscriptGetter", testSubscriptGetter),
]
}

extension BenchmarkTests {
static let __allTests = [
("testMutatingTestPointsCount", testMutatingTestPointsCount),
("testNonMutatingTestPointsCount", testNonMutatingTestPointsCount),
]
}

extension DictionaryTests {
static let __allTests = [
("testCount", testCount),
("testEqualityOperator", testEqualityOperator),
("testFilter", testFilter),
("testFirst", testFirst),
("testIndex", testIndex),
("testInequalityOperator", testInequalityOperator),
("testIsEmpty", testIsEmpty),
("testKeys", testKeys),
("testRemoveAll", testRemoveAll),
("testRemoveValueHit", testRemoveValueHit),
("testRemoveValueMiss", testRemoveValueMiss),
("testSubscriptGetter", testSubscriptGetter),
("testUpdateValueHit", testUpdateValueHit),
("testUpdateValueMiss", testUpdateValueMiss),
("testValues", testValues),
]
}

extension PerformanceTestingTests {
static let __allTests = [
("testConstant", testConstant),
("testCubicSlopeOne", testCubicSlopeOne),
("testCubicSlopeThree", testCubicSlopeThree),
("testExponentialBaseTwoSlopeOne", testExponentialBaseTwoSlopeOne),
("testExponentialBaseTwoSlopeThree", testExponentialBaseTwoSlopeThree),
("testLinearSlopeOne", testLinearSlopeOne),
("testLinearSlopeThree", testLinearSlopeThree),
("testLogarithmicBaseESlopeOne", testLogarithmicBaseESlopeOne),
("testLogarithmicBaseESlopeThree", testLogarithmicBaseESlopeThree),
("testLogarithmicBaseTwoSlopeOne", testLogarithmicBaseTwoSlopeOne),
("testLogarithmicBaseTwoSlopeThree", testLogarithmicBaseTwoSlopeThree),
("testQuadraticSlopeOne", testQuadraticSlopeOne),
("testQuadraticSlopeThree", testQuadraticSlopeThree),
("testSquareRootSlopeOne", testSquareRootSlopeOne),
("testSquareRootSlopeThree", testSquareRootSlopeThree),
]
}

extension SetTests {
static let __allTests = [
("testContainsHit", testContainsHit),
("testContainsMiss", testContainsMiss),
("testCount", testCount),
("testFilter", testFilter),
("testFirst", testFirst),
("testInsert", testInsert),
("testIsEmpty", testIsEmpty),
("testRemoveFirst", testRemoveFirst),
("testRemoveHit", testRemoveHit),
("testRemoveMiss", testRemoveMiss),
("testUnionWithConstantSizedOther", testUnionWithConstantSizedOther),
("testUnionWithLinearSizedOther", testUnionWithLinearSizedOther),
]
}

#if !os(macOS)
public func __allTests() -> [XCTestCaseEntry] {
return [
testCase(AlgorithmComplexityTests.__allTests),
testCase(ArrayTests.__allTests),
testCase(BenchmarkTests.__allTests),
testCase(DictionaryTests.__allTests),
testCase(PerformanceTestingTests.__allTests),
testCase(SetTests.__allTests),
]
}
#endif

0 comments on commit d48417c

Please sign in to comment.