Skip to content

Add benchmark for quadratic hash performance #7617

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
Feb 28, 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 @@ -48,6 +48,7 @@ set(SWIFT_BENCH_MODULES
single-source/GlobalClass
single-source/Hanoi
single-source/Hash
single-source/HashQuadratic
single-source/Histogram
single-source/Integrate
single-source/IterateData
Expand Down
15 changes: 12 additions & 3 deletions benchmark/scripts/generate_harness/CMakeLists.txt_template
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,18 @@ if(NOT SWIFT_LIBRARY_PATH)
set(SWIFT_LIBRARY_PATH "${tmp_dir}/lib/swift")
endif()

runcmd(COMMAND "xcrun" "-toolchain" "${SWIFT_DARWIN_XCRUN_TOOLCHAIN}" "-f" "clang"
VARIABLE CLANG_EXEC
ERROR "Unable to find Clang driver")
# If the CMAKE_C_COMPILER is already clang, don't find it again,
# thus allowing the --host-cc build-script argument to work here.
get_filename_component(c_compiler ${CMAKE_C_COMPILER} NAME)

if(${c_compiler} STREQUAL "clang")
set(CLANG_EXEC ${CMAKE_C_COMPILER})
else()
runcmd(COMMAND "xcrun" "-toolchain" "${SWIFT_DARWIN_XCRUN_TOOLCHAIN}" "-f" "clang"
VARIABLE CLANG_EXEC
ERROR "Unable to find Clang driver")
endif()


# You have to delete CMakeCache.txt in the swift build to force a
# reconfiguration.
Expand Down
33 changes: 33 additions & 0 deletions benchmark/single-source/HashQuadratic.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===--- HashQuadratic.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

let size = 3_000_000

@inline(never)
public func run_HashQuadratic(_ N: Int) {
for _ in 1...N {
var dict1: [Int: Int] = [:]
for i in 0..<size {
dict1[i] = i * 2
}

var dict2: [Int: Int] = [:]
for (k, v) in dict1 {
dict2[k] = v
}

CheckResults(dict2[size/2] == dict2[size/2],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@natecook1000 My apologies for missing this. It appears you're trying to compare dict1 and dict2 but you have dict2 on both sides.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're so right! I think that will still defeat inlining, but I'll fix ASAP. Thanks!

"Incorrect results in HashQuadratic")
}
}
25 changes: 14 additions & 11 deletions benchmark/utils/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import Fibonacci
import GlobalClass
import Hanoi
import Hash
import HashQuadratic
import Histogram
import Integrate
import IterateData
Expand Down Expand Up @@ -113,28 +114,28 @@ precommitTests = [
"Array2D": run_Array2D,
"ArrayAppend": run_ArrayAppend,
"ArrayAppendArrayOfInt": run_ArrayAppendArrayOfInt,
"ArrayAppendAscii": run_ArrayAppendAscii,
"ArrayAppendFromGeneric": run_ArrayAppendFromGeneric,
"ArrayAppendGenericStructs": run_ArrayAppendGenericStructs,
"ArrayAppendLatin1": run_ArrayAppendLatin1,
"ArrayAppendLazyMap": run_ArrayAppendLazyMap,
"ArrayAppendOptionals": run_ArrayAppendOptionals,
"ArrayAppendRepeatCol": run_ArrayAppendRepeatCol,
"ArrayAppendReserved": run_ArrayAppendReserved,
"ArrayAppendSequence": run_ArrayAppendSequence,
"ArrayAppendStrings": run_ArrayAppendStrings,
"ArrayAppendASCII": run_ArrayAppendAscii,
"ArrayAppendLatin1": run_ArrayAppendLatin1,
"ArrayAppendUTF16": run_ArrayAppendUTF16,
"ArrayAppendToFromGeneric": run_ArrayAppendToFromGeneric,
"ArrayAppendToGeneric": run_ArrayAppendToGeneric,
"ArrayPlusEqualSingleElementCollection": run_ArrayPlusEqualSingleElementCollection,
"ArrayPlusEqualFiveElementCollection": run_ArrayPlusEqualFiveElementCollection,
"ArrayAppendUTF16": run_ArrayAppendUTF16,
"ArrayInClass": run_ArrayInClass,
"ArrayLiteral": run_ArrayLiteral,
"ArrayOfGenericPOD": run_ArrayOfGenericPOD,
"ArrayOfGenericRef": run_ArrayOfGenericRef,
"ArrayOfPOD": run_ArrayOfPOD,
"ArrayOfRef": run_ArrayOfRef,
"ArrayPlusEqualArrayOfInt": run_ArrayPlusEqualArrayOfInt,
"ArrayPlusEqualFiveElementCollection": run_ArrayPlusEqualFiveElementCollection,
"ArrayPlusEqualSingleElementCollection": run_ArrayPlusEqualSingleElementCollection,
"ArraySubscript": run_ArraySubscript,
"ArrayValueProp": run_ArrayValueProp,
"ArrayValueProp2": run_ArrayValueProp2,
Expand Down Expand Up @@ -164,6 +165,7 @@ precommitTests = [
"ErrorHandling": run_ErrorHandling,
"GlobalClass": run_GlobalClass,
"Hanoi": run_Hanoi,
"HashQuadratic": run_HashQuadratic,
"HashTest": run_HashTest,
"Histogram": run_Histogram,
"Integrate": run_Integrate,
Expand All @@ -172,15 +174,16 @@ precommitTests = [
"LinkedList": run_LinkedList,
"MapReduce": run_MapReduce,
"MapReduceAnyCollection": run_MapReduceAnyCollection,
"MapReduceShort": run_MapReduceShort,
"MapReduceSequence": run_MapReduceSequence,
"MapReduceLazySequence": run_MapReduceLazySequence,
"MapReduceAnyCollectionShort": run_MapReduceAnyCollectionShort,
"MapReduceClass": run_MapReduceClass,
"MapReduceClassShort": run_MapReduceClassShort,
"MapReduceLazyCollection": run_MapReduceLazyCollection,
"MapReduceLazyCollectionShort": run_MapReduceLazyCollectionShort,
"MapReduceString": run_MapReduceString,
"MapReduceLazySequence": run_MapReduceLazySequence,
"MapReduceSequence": run_MapReduceSequence,
"MapReduceShort": run_MapReduceShort,
"MapReduceShortString": run_MapReduceShortString,
"MapReduceClass": run_MapReduceClass,
"MapReduceClassShort": run_MapReduceClassShort,
"MapReduceString": run_MapReduceString,
"Memset": run_Memset,
"MonteCarloE": run_MonteCarloE,
"MonteCarloPi": run_MonteCarloPi,
Expand Down