Skip to content

Commit 252af7d

Browse files
authored
Merge pull request #7617 from natecook1000/nc-hash-quadtest
Add benchmark for quadratic hash performance
2 parents fbe945b + c53e8d6 commit 252af7d

File tree

4 files changed

+60
-14
lines changed

4 files changed

+60
-14
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ set(SWIFT_BENCH_MODULES
4848
single-source/GlobalClass
4949
single-source/Hanoi
5050
single-source/Hash
51+
single-source/HashQuadratic
5152
single-source/Histogram
5253
single-source/Integrate
5354
single-source/IterateData

benchmark/scripts/generate_harness/CMakeLists.txt_template

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,18 @@ if(NOT SWIFT_LIBRARY_PATH)
6767
set(SWIFT_LIBRARY_PATH "${tmp_dir}/lib/swift")
6868
endif()
6969

70-
runcmd(COMMAND "xcrun" "-toolchain" "${SWIFT_DARWIN_XCRUN_TOOLCHAIN}" "-f" "clang"
71-
VARIABLE CLANG_EXEC
72-
ERROR "Unable to find Clang driver")
70+
# If the CMAKE_C_COMPILER is already clang, don't find it again,
71+
# thus allowing the --host-cc build-script argument to work here.
72+
get_filename_component(c_compiler ${CMAKE_C_COMPILER} NAME)
73+
74+
if(${c_compiler} STREQUAL "clang")
75+
set(CLANG_EXEC ${CMAKE_C_COMPILER})
76+
else()
77+
runcmd(COMMAND "xcrun" "-toolchain" "${SWIFT_DARWIN_XCRUN_TOOLCHAIN}" "-f" "clang"
78+
VARIABLE CLANG_EXEC
79+
ERROR "Unable to find Clang driver")
80+
endif()
81+
7382

7483
# You have to delete CMakeCache.txt in the swift build to force a
7584
# reconfiguration.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===--- HashQuadratic.swift ----------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import TestsUtils
14+
15+
let size = 3_000_000
16+
17+
@inline(never)
18+
public func run_HashQuadratic(_ N: Int) {
19+
for _ in 1...N {
20+
var dict1: [Int: Int] = [:]
21+
for i in 0..<size {
22+
dict1[i] = i * 2
23+
}
24+
25+
var dict2: [Int: Int] = [:]
26+
for (k, v) in dict1 {
27+
dict2[k] = v
28+
}
29+
30+
CheckResults(dict2[size/2] == dict2[size/2],
31+
"Incorrect results in HashQuadratic")
32+
}
33+
}

benchmark/utils/main.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import Fibonacci
5353
import GlobalClass
5454
import Hanoi
5555
import Hash
56+
import HashQuadratic
5657
import Histogram
5758
import Integrate
5859
import IterateData
@@ -113,28 +114,28 @@ precommitTests = [
113114
"Array2D": run_Array2D,
114115
"ArrayAppend": run_ArrayAppend,
115116
"ArrayAppendArrayOfInt": run_ArrayAppendArrayOfInt,
117+
"ArrayAppendAscii": run_ArrayAppendAscii,
116118
"ArrayAppendFromGeneric": run_ArrayAppendFromGeneric,
117119
"ArrayAppendGenericStructs": run_ArrayAppendGenericStructs,
120+
"ArrayAppendLatin1": run_ArrayAppendLatin1,
118121
"ArrayAppendLazyMap": run_ArrayAppendLazyMap,
119122
"ArrayAppendOptionals": run_ArrayAppendOptionals,
120123
"ArrayAppendRepeatCol": run_ArrayAppendRepeatCol,
121124
"ArrayAppendReserved": run_ArrayAppendReserved,
122125
"ArrayAppendSequence": run_ArrayAppendSequence,
123126
"ArrayAppendStrings": run_ArrayAppendStrings,
124-
"ArrayAppendASCII": run_ArrayAppendAscii,
125-
"ArrayAppendLatin1": run_ArrayAppendLatin1,
126-
"ArrayAppendUTF16": run_ArrayAppendUTF16,
127127
"ArrayAppendToFromGeneric": run_ArrayAppendToFromGeneric,
128128
"ArrayAppendToGeneric": run_ArrayAppendToGeneric,
129-
"ArrayPlusEqualSingleElementCollection": run_ArrayPlusEqualSingleElementCollection,
130-
"ArrayPlusEqualFiveElementCollection": run_ArrayPlusEqualFiveElementCollection,
129+
"ArrayAppendUTF16": run_ArrayAppendUTF16,
131130
"ArrayInClass": run_ArrayInClass,
132131
"ArrayLiteral": run_ArrayLiteral,
133132
"ArrayOfGenericPOD": run_ArrayOfGenericPOD,
134133
"ArrayOfGenericRef": run_ArrayOfGenericRef,
135134
"ArrayOfPOD": run_ArrayOfPOD,
136135
"ArrayOfRef": run_ArrayOfRef,
137136
"ArrayPlusEqualArrayOfInt": run_ArrayPlusEqualArrayOfInt,
137+
"ArrayPlusEqualFiveElementCollection": run_ArrayPlusEqualFiveElementCollection,
138+
"ArrayPlusEqualSingleElementCollection": run_ArrayPlusEqualSingleElementCollection,
138139
"ArraySubscript": run_ArraySubscript,
139140
"ArrayValueProp": run_ArrayValueProp,
140141
"ArrayValueProp2": run_ArrayValueProp2,
@@ -164,6 +165,7 @@ precommitTests = [
164165
"ErrorHandling": run_ErrorHandling,
165166
"GlobalClass": run_GlobalClass,
166167
"Hanoi": run_Hanoi,
168+
"HashQuadratic": run_HashQuadratic,
167169
"HashTest": run_HashTest,
168170
"Histogram": run_Histogram,
169171
"Integrate": run_Integrate,
@@ -172,15 +174,16 @@ precommitTests = [
172174
"LinkedList": run_LinkedList,
173175
"MapReduce": run_MapReduce,
174176
"MapReduceAnyCollection": run_MapReduceAnyCollection,
175-
"MapReduceShort": run_MapReduceShort,
176-
"MapReduceSequence": run_MapReduceSequence,
177-
"MapReduceLazySequence": run_MapReduceLazySequence,
177+
"MapReduceAnyCollectionShort": run_MapReduceAnyCollectionShort,
178+
"MapReduceClass": run_MapReduceClass,
179+
"MapReduceClassShort": run_MapReduceClassShort,
178180
"MapReduceLazyCollection": run_MapReduceLazyCollection,
179181
"MapReduceLazyCollectionShort": run_MapReduceLazyCollectionShort,
180-
"MapReduceString": run_MapReduceString,
182+
"MapReduceLazySequence": run_MapReduceLazySequence,
183+
"MapReduceSequence": run_MapReduceSequence,
184+
"MapReduceShort": run_MapReduceShort,
181185
"MapReduceShortString": run_MapReduceShortString,
182-
"MapReduceClass": run_MapReduceClass,
183-
"MapReduceClassShort": run_MapReduceClassShort,
186+
"MapReduceString": run_MapReduceString,
184187
"Memset": run_Memset,
185188
"MonteCarloE": run_MonteCarloE,
186189
"MonteCarloPi": run_MonteCarloPi,

0 commit comments

Comments
 (0)