Skip to content

Commit 6ed5082

Browse files
committed
---
yaml --- r: 347123 b: refs/heads/master c: 88d1183 h: refs/heads/master i: 347121: b6f1f00 347119: 556d8a9
1 parent be2cd35 commit 6ed5082

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: d8d21e792ce98b73b8267590ac592af2f504858c
2+
refs/heads/master: 88d1183e589363a9722c7db5090a55a5d1ec187b
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/validation-test/stdlib/StringMemoryTest.swift

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ import Foundation
1212
let str = "abcdefg\u{A758}hijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\u{A759}"
1313
let str2 = "abcdefg\u{A759}hijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\u{A758}"
1414

15+
16+
@inline(never)
17+
func getMemoryUsage() -> Int {
18+
var usage = rusage()
19+
getrusage(RUSAGE_SELF, &usage)
20+
return usage.ru_maxrss
21+
}
22+
1523
@inline(never)
1624
func lookup(_ str: String, _ dict: [String: Int]) -> Bool {
1725
if let _ = dict[str] {
@@ -30,35 +38,44 @@ func lowercase(_ str: String) -> String {
3038
return str.lowercased()
3139
}
3240

41+
@inline(never)
42+
func runTest() {
43+
for _ in 0 ..< 10_0000 {
44+
if lookup("\u{1F1E7}\u{1F1E7}", dict) {
45+
print("Found?!")
46+
}
47+
if uppercase(str) == "A" {
48+
print("Found?!")
49+
}
50+
if lowercase(str2) == "A" {
51+
print("Found?!")
52+
}
53+
}
54+
}
55+
56+
3357
/// Make sure the hash function does not leak.
3458

3559
let dict = [ "foo" : 1]
36-
for _ in 0 ..< 10_000_000 {
37-
if lookup("\u{1F1E7}\u{1F1E7}", dict) {
38-
print("Found?!")
39-
}
40-
if uppercase(str) == "A" {
41-
print("Found?!")
42-
}
43-
if lowercase(str2) == "A" {
44-
print("Found?!")
45-
}
46-
}
60+
61+
let baseUsage = getMemoryUsage()
62+
runTest()
63+
let firstRun = getMemoryUsage () - baseUsage
64+
runTest()
65+
runTest()
66+
let secondRun = getMemoryUsage () - baseUsage
4767

4868
// CHECK-NOT: Found?!
4969
// CHECK: Not found
5070

5171
print("Not found")
5272

53-
var usage = rusage()
54-
getrusage(RUSAGE_SELF, &usage)
55-
5673
// CHECK: success
5774
// CHECK-NOT: failure
5875

5976
// We should not need 50MB for this.
60-
if usage.ru_maxrss > 50 * 1024 * 1024 {
61-
print("failure - should not need 50MB!")
77+
if firstRun * 2 < secondRun {
78+
print("failure - should not linearly increase")
6279
} else {
6380
print("success")
6481
}

0 commit comments

Comments
 (0)