-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add performance and allocation tests for canonical form headers (#1953)
Motivation: To justify performance changes we need to measure the code being changed. We believe that `HTTPHeaders.subscript(canonicalForm:)` is a little slow. Modifications: - Add allocation and performance tests for fetching header values in their canonical form Results: More benchmarks!
- Loading branch information
Showing
7 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...Tests/tests_04_performance/test_01_resources/test_get_100000_headers_canonical_form.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftNIO open source project | ||
// | ||
// Copyright (c) 2021 Apple Inc. and the SwiftNIO project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
import NIOHTTP1 | ||
|
||
func run(identifier: String) { | ||
measure(identifier: identifier) { | ||
let headers: HTTPHeaders = ["key": "no,trimming"] | ||
var count = 0 | ||
for _ in 0..<100_000 { | ||
count &+= headers[canonicalForm: "key"].count | ||
} | ||
return count | ||
} | ||
|
||
measure(identifier: identifier + "_trimming_whitespace") { | ||
let headers: HTTPHeaders = ["key": " some , trimming "] | ||
var count = 0 | ||
for _ in 0..<100_000 { | ||
count &+= headers[canonicalForm: "key"].count | ||
} | ||
return count | ||
} | ||
|
||
measure(identifier: identifier + "_trimming_whitespace_from_short_string") { | ||
// first components has length > 15 with whitespace and <= 15 without. | ||
let headers: HTTPHeaders = ["key": " smallString ,whenStripped"] | ||
var count = 0 | ||
for _ in 0..<100_000 { | ||
count &+= headers[canonicalForm: "key"].count | ||
} | ||
return count | ||
} | ||
|
||
measure(identifier: identifier + "_trimming_whitespace_from_long_string") { | ||
let headers: HTTPHeaders = ["key": " moreThan15CharactersWithAndWithoutWhitespace ,anotherValue"] | ||
var count = 0 | ||
for _ in 0..<100_000 { | ||
count &+= headers[canonicalForm: "key"].count | ||
} | ||
return count | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters