Skip to content

Commit

Permalink
Add help message to benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
nvzqz committed Nov 25, 2016
1 parent 999d094 commit 9bdfedb
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
2 changes: 2 additions & 0 deletions RandomKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
528200F11BC9FA42001FDD58 /* RandomKit Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "RandomKit Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
528200F31BC9FA42001FDD58 /* RandomKitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RandomKitTests.swift; sourceTree = "<group>"; };
528200F51BC9FA42001FDD58 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
52879EB61DE7BCDF004EF9FE /* Help.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Help.swift; sourceTree = "<group>"; };
52A248B41DC68200004C9991 /* Strideable+RandomKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Strideable+RandomKit.swift"; sourceTree = "<group>"; };
52ADBE761DE54A98004CB28A /* RandomWithMaxWidth.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RandomWithMaxWidth.swift; sourceTree = "<group>"; };
52ADBE7B1DE54BBF004CB28A /* RandomWithExactWidth.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RandomWithExactWidth.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -324,6 +325,7 @@
isa = PBXGroup;
children = (
521771671DE6DF9C00DD4584 /* main.swift */,
52879EB61DE7BCDF004EF9FE /* Help.swift */,
5217716D1DE6F0D600DD4584 /* Benchmark.swift */,
521771681DE6E4E900DD4584 /* Style.swift */,
5217716E1DE7024200DD4584 /* Extensions.swift */,
Expand Down
70 changes: 70 additions & 0 deletions Sources/benchmark/Help.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// Help.swift
// RandomKit Benchmark
//
// The MIT License (MIT)
//
// Copyright (c) 2015-2016 Nikolai Vazquez
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

import Foundation

func printHelpAndExit() -> Never {
var message = "RandomKit benchmark\n"
message += "\n"
message += "Flags:\n"
message += "\n"
message += " --help Print this help message\n"
message += " --no-color Output no color\n"
message += "\n"
message += " --count, -c COUNT The number of times to benchmark (default: 10000000)\n"
message += "\n"
message += " --all, -a Benchmark all of the following\n"
message += " --all-generators Benchmark all generators\n"
message += " --all-integers Benchmark all integer types\n"
message += " --all-protocols Benchmark all protocols\n"
message += "\n"
message += " --array COUNT Benchmark both safe and unsafe random arrays\n"
message += " Default count is 100\n"
message += " --array-safe COUNT Benchmark safe random arrays\n"
message += " Default count is 100\n"
message += " --array-unsafe COUNT Benchmark unsafe random arrays\n"
message += " Default count is 100\n"
message += "\n"
message += "Generators:\n"
message += "\n"
message += " --xoroshiro Use both safe and unsafe xoroshiro generators\n"
message += " --xoroshiro-safe Use safe xoroshiro generator\n"
message += " --xoroshiro-unsafe Use unsafe xoroshiro generator\n"
message += " --arc4random Use arc4random generator\n"
message += " --dev Use both /dev/random and /dev/urandom generators\n"
message += " --dev-random Use /dev/random generator\n"
message += " --dev-urandom Use /dev/urandom generator\n"
message += "\n"
message += "Protocols: (passed as arguments)\n"
message += "\n"
message += " Random\n"
message += " RandomToValue\n"
message += " RandomThroughValue\n"
message += " RandomWithinRange\n"
print(message)
exit(EXIT_SUCCESS)
}
4 changes: 4 additions & 0 deletions Sources/benchmark/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ func int(after arg: String) -> Int? {

let styleOutput = !contains("--no-color")

if contains("--help") {
printHelpAndExit()
}

let benchmarkAll = contains("--all") || contains("-a")
let benchmarkAllGenerators = benchmarkAll || contains("--all-generators")
let benchmarkAllIntegers = benchmarkAll || contains("--all-integers")
Expand Down

0 comments on commit 9bdfedb

Please sign in to comment.