Skip to content

Commit 49b50bc

Browse files
Kevin Ballardlilyball
authored andcommitted
Add benchmark for iterating Data
1 parent 4a872ed commit 49b50bc

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ set(SWIFT_BENCH_MODULES
3737
single-source/CaptureProp
3838
single-source/Chars
3939
single-source/ClassArrayGetter
40+
single-source/Data
4041
single-source/DeadArray
4142
single-source/DictionaryBridge
4243
single-source/DictionaryLiteral

benchmark/single-source/Data.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===--- Data.swift -------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import TestsUtils
14+
import Foundation
15+
16+
@inline(never)
17+
func generateData() -> Data {
18+
var data = Data(count: 16 * 1024)
19+
data.withUnsafeMutableBytes { (ptr: UnsafeMutablePointer<UInt8>) -> () in
20+
for i in 0..<data.count {
21+
ptr[i] = UInt8(i % 23)
22+
}
23+
}
24+
return data
25+
}
26+
27+
@inline(never)
28+
public func run_IterateData(_ N: Int) {
29+
let data = generateData()
30+
31+
for _ in 0...10*N {
32+
_ = data.reduce(0, +)
33+
}
34+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import Calculator
3838
import CaptureProp
3939
import Chars
4040
import ClassArrayGetter
41+
import Data
4142
import DeadArray
4243
import DictTest
4344
import DictTest2
@@ -141,6 +142,7 @@ precommitTests = [
141142
"HashTest": run_HashTest,
142143
"Histogram": run_Histogram,
143144
"Integrate": run_Integrate,
145+
"IterateData": run_IterateData,
144146
"Join": run_Join,
145147
"LinkedList": run_LinkedList,
146148
"MapReduce": run_MapReduce,

0 commit comments

Comments
 (0)