Skip to content

[benchmark] Add RangeIteration benchmarks #12193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ set(SWIFT_BENCH_MODULES
single-source/RC4
single-source/RGBHistogram
single-source/RangeAssignment
single-source/RangeIteration
single-source/RecursiveOwnedParameter
single-source/ReduceInto
single-source/ReversedCollections
Expand Down
77 changes: 77 additions & 0 deletions benchmark/single-source/RangeIteration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//===--- RangeAssignment.swift --------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import TestsUtils

public let RangeIteration = [
BenchmarkInfo(
name: "RangeIterationSigned",
runFunction: run_RangeIterationSigned,
tags: [.validation, .api]
),
BenchmarkInfo(
name: "RangeIterationSigned64",
runFunction: run_RangeIterationSigned64,
tags: [.validation, .api]
),
BenchmarkInfo(
name: "RangeIterationUnsigned",
runFunction: run_RangeIterationUnsigned,
tags: [.validation, .api]
),
]

public var check: UInt64 = 0

@inline(never)
func sum(_ x: UInt64, _ y: UInt64) -> UInt64 {
return x &+ y
}

@inline(never)
public func run_RangeIterationSigned(_ N: Int) {
let range = 0..<100000
check = 0
for _ in 1...N {
for e in range {
check = sum(check, UInt64(e))
}
}

CheckResults(check == 4999950000 * UInt64(N))
}

@inline(never)
public func run_RangeIterationSigned64(_ N: Int) {
let range: CountableRange<Int64> = 0..<100000
check = 0
for _ in 1...N {
for e in range {
check = sum(check, UInt64(e))
}
}

CheckResults(check == 4999950000 * UInt64(N))
}

@inline(never)
public func run_RangeIterationUnsigned(_ N: Int) {
let range: CountableRange<UInt> = 0..<100000
check = 0
for _ in 1...N {
for e in range {
check = sum(check, UInt64(e))
}
}

CheckResults(check == 4999950000 * UInt64(N))
}
9 changes: 3 additions & 6 deletions benchmark/utils/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@
//
//===----------------------------------------------------------------------===//

////////////////////////////////////////////////////////////////////////////////
// WARNING: This file is manually generated from .gyb template and should not
// be directly modified. Instead, make changes to main.swift.gyb and run
// scripts/generate_harness/generate_harness.py to regenerate this file.
////////////////////////////////////////////////////////////////////////////////

// This is just a driver for performance overview tests.

import TestsUtils
import DriverUtils
import Ackermann
Expand Down Expand Up @@ -96,6 +91,7 @@ import ProtocolDispatch2
import RC4
import RGBHistogram
import RangeAssignment
import RangeIteration
import RecursiveOwnedParameter
import ReduceInto
import ReversedCollections
Expand Down Expand Up @@ -214,6 +210,7 @@ registerBenchmark(ProtocolDispatch2)
registerBenchmark(RC4Test)
registerBenchmark(RGBHistogram)
registerBenchmark(RangeAssignment)
registerBenchmark(RangeIteration)
registerBenchmark(RecursiveOwnedParameter)
registerBenchmark(ReduceInto)
registerBenchmark(ReversedCollections)
Expand Down