mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This function mixes the bits in the hash value, which improves Dictionary performance for keys with bad hashes. PrecommitBenchmark changes with greater than 7% difference: ``````````Dictionary2`,```1456.00`,```1508.00`,```1502.00`,````624.00`,````607.00`,````592.00`,`864.00`,``145.9% ``````````Dictionary3`,```1379.00`,```1439.00`,```1408.00`,````585.00`,````567.00`,````552.00`,`827.00`,``149.8% ````````````Histogram`,````850.00`,````849.00`,````851.00`,```1053.00`,```1049.00`,```1048.00`,`199.00`,``-19.0% ````````````````Prims`,```1999.00`,```2005.00`,```2018.00`,```1734.00`,```1689.00`,```1701.00`,`310.00`,```18.4% ``````````StrSplitter`,```2365.00`,```2334.00`,```2316.00`,```1979.00`,```1997.00`,```2000.00`,`337.00`,```17.0% ```````````````TwoSum`,```1551.00`,```1568.00`,```1556.00`,```1771.00`,```1741.00`,```1716.00`,`165.00`,```-9.6% Regressions are in benchmarks that use `Int` as dictionary key: we are just doing more work than previously (hashing an `Int` was an identity function). rdar://17962402 Swift SVN r21142
53 lines
1.2 KiB
Swift
53 lines
1.2 KiB
Swift
// RUN: %target-build-swift -module-name a %s -o %t.out
|
|
// RUN: %target-run %t.out
|
|
|
|
//
|
|
// This file contains reflection tests that depend on hash values.
|
|
// Don't add other tests here.
|
|
//
|
|
|
|
import StdlibUnittest
|
|
|
|
var Reflection = TestCase("Reflection")
|
|
|
|
Reflection.test("Dictionary/Empty") {
|
|
let dict = [Int : Int]()
|
|
|
|
var output = ""
|
|
dump(dict, &output)
|
|
|
|
var expected = "- 0 key/value pairs\n"
|
|
|
|
expectEqual(expected, output)
|
|
}
|
|
|
|
Reflection.test("Dictionary") {
|
|
let dict = [ "One": 1, "Two": 2, "Three": 3, "Four": 4, "Five": 5 ]
|
|
|
|
var output = ""
|
|
dump(dict, &output)
|
|
|
|
var expected = ""
|
|
expected += "▿ 5 key/value pairs\n"
|
|
expected += " ▿ [0]: (2 elements)\n"
|
|
expected += " - .0: Five\n"
|
|
expected += " - .1: 5\n"
|
|
expected += " ▿ [1]: (2 elements)\n"
|
|
expected += " - .0: Two\n"
|
|
expected += " - .1: 2\n"
|
|
expected += " ▿ [2]: (2 elements)\n"
|
|
expected += " - .0: One\n"
|
|
expected += " - .1: 1\n"
|
|
expected += " ▿ [3]: (2 elements)\n"
|
|
expected += " - .0: Three\n"
|
|
expected += " - .1: 3\n"
|
|
expected += " ▿ [4]: (2 elements)\n"
|
|
expected += " - .0: Four\n"
|
|
expected += " - .1: 4\n"
|
|
|
|
expectEqual(expected, output)
|
|
}
|
|
|
|
runAllTests()
|
|
|