-   Notifications  You must be signed in to change notification settings 
- Fork 9
 adopt package-benchmark #41 
 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
Changes from 9 commits
7a75577 c8484af ae0fd01 6e2373e 759644c b5847f2 f2f2ea2 91c4a1f 14b336f 5afaf4f 8d8077d fc5a1ea 29fef29 b69fe86 753ca9a File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| .DS_Store | ||
| /.build | ||
| /Packages | ||
| xcuserdata/ | ||
| DerivedData/ | ||
| .swiftpm/configuration/registries.json | ||
| .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
| .netrc | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the swift-memcache-gsoc open source project | ||
| // | ||
| // Copyright (c) 2023 Apple Inc. and the swift-memcache-gsoc project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of swift-memcache-gsoc project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|  | ||
| import Benchmark | ||
| import Foundation | ||
| import Memcache | ||
| import NIOCore | ||
| import NIOPosix | ||
|  | ||
| let benchmarks = { | ||
| let defaultMetrics: [BenchmarkMetric] = [ | ||
| .mallocCountTotal, | ||
| .mallocCountLarge, | ||
| .mallocCountTotal, | ||
| .memoryLeaked, | ||
| .allocatedResidentMemory, | ||
| ] | ||
|  | ||
| Benchmark("Set Request", configuration: .init(metrics: defaultMetrics)) { benchmark in | ||
| try await withThrowingTaskGroup(of: Void.self) { group in | ||
|   | ||
|  | ||
| let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
|   | ||
| let memcacheConnection = MemcacheConnection(host: "memcached", port: 11211, eventLoopGroup: eventLoopGroup) | ||
|  | ||
| group.addTask { try await memcacheConnection.run() } | ||
|  | ||
| let setValue = "bar" | ||
| try await memcacheConnection.set("foo", value: setValue) | ||
|  | ||
| for _ in benchmark.scaledIterations { | ||
| let getValue: String? = try await memcacheConnection.get("foo") | ||
| assert(getValue == setValue, "Value retrieved from Memcache does not match the set value") | ||
|   | ||
| } | ||
|  | ||
| group.cancelAll() | ||
| } | ||
| } | ||
|  | ||
| Benchmark("Set with TTL Request", configuration: .init(metrics: defaultMetrics)) { benchmark in | ||
| try await withThrowingTaskGroup(of: Void.self) { group in | ||
|  | ||
| let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
| let memcacheConnection = MemcacheConnection(host: "memcached", port: 11211, eventLoopGroup: eventLoopGroup) | ||
|  | ||
| group.addTask { try await memcacheConnection.run() } | ||
|  | ||
| let setValue = "foo" | ||
| let now = ContinuousClock.Instant.now | ||
| let expirationTime = now.advanced(by: .seconds(90)) | ||
| let timeToLive = TimeToLive.expiresAt(expirationTime) | ||
| try await memcacheConnection.set("bar", value: setValue, timeToLive: timeToLive) | ||
|  | ||
| for _ in benchmark.scaledIterations { | ||
| let getValue: String? = try await memcacheConnection.get("foo") | ||
| assert(getValue == setValue, "Value retrieved from Memcache does not match the set value") | ||
| } | ||
|  | ||
| group.cancelAll() | ||
| } | ||
| } | ||
|  | ||
| Benchmark("Delete Request", configuration: .init(metrics: defaultMetrics)) { benchmark in | ||
|   | ||
| try await withThrowingTaskGroup(of: Void.self) { group in | ||
| let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
| let memcacheConnection = MemcacheConnection(host: "memcached", port: 11211, eventLoopGroup: eventLoopGroup) | ||
|  | ||
| group.addTask { try await memcacheConnection.run() } | ||
| let setValue = "foo" | ||
| try await memcacheConnection.set("bar", value: setValue) | ||
|  | ||
| for _ in benchmark.scaledIterations { | ||
| try await memcacheConnection.delete("bar") | ||
| } | ||
|  | ||
| group.cancelAll() | ||
| } | ||
| } | ||
|  | ||
| Benchmark("Increment Request", configuration: .init(metrics: defaultMetrics)) { benchmark in | ||
| try await withThrowingTaskGroup(of: Void.self) { group in | ||
| let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
| let memcacheConnection = MemcacheConnection(host: "memcached", port: 11211, eventLoopGroup: eventLoopGroup) | ||
|  | ||
| group.addTask { try await memcacheConnection.run() } | ||
| let initialValue = 1 | ||
| try await memcacheConnection.set("increment", value: initialValue) | ||
|  | ||
| for _ in benchmark.scaledIterations { | ||
| let incrementAmount = 100 | ||
| try await memcacheConnection.increment("increment", amount: incrementAmount) | ||
|  | ||
| let newValue: Int? = try await memcacheConnection.get("increment") | ||
| assert(newValue == initialValue + incrementAmount, "Incremented value is incorrect") | ||
| } | ||
| group.cancelAll() | ||
| } | ||
| } | ||
|  | ||
| Benchmark("Decrement Request", configuration: .init(metrics: defaultMetrics)) { benchmark in | ||
| try await withThrowingTaskGroup(of: Void.self) { group in | ||
| let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
| let memcacheConnection = MemcacheConnection(host: "memcached", port: 11211, eventLoopGroup: eventLoopGroup) | ||
|  | ||
| group.addTask { try await memcacheConnection.run() } | ||
| let initialValue = 100 | ||
| try await memcacheConnection.set("decrement", value: initialValue) | ||
|  | ||
| for _ in benchmark.scaledIterations { | ||
| let decrementAmount = 10 | ||
| try await memcacheConnection.decrement("decrement", amount: decrementAmount) | ||
|  | ||
| let newValue: Int? = try await memcacheConnection.get("decrement") | ||
| assert(newValue == initialValue - decrementAmount, "decrement value is incorrect") | ||
| } | ||
| group.cancelAll() | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // swift-tools-version: 5.7 | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the SwiftCertificates open source project | ||
| // | ||
| // Copyright (c) 2023 Apple Inc. and the SwiftCertificates project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of SwiftCertificates project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|  | ||
| import PackageDescription | ||
|  | ||
| let package = Package( | ||
| name: "Benchmarks", | ||
| platforms: [ | ||
| .macOS(.v13), | ||
| ], | ||
| dependencies: [ | ||
| .package(name: "swift-memcache-gsoc", path: "../"), | ||
| .package(url: "https://github.com/ordo-one/package-benchmark.git", from: "1.11.1"), | ||
| .package(url: "https://github.com/apple/swift-nio.git", from: "2.56.0"), | ||
| ], | ||
| targets: [ | ||
| .target( | ||
| name: "Benchmarks"), | ||
| .testTarget( | ||
| name: "BenchmarksTests", | ||
| dependencies: ["Benchmarks"] | ||
| ), | ||
|   | ||
| ] | ||
| ) | ||
| // Benchmark of MemcacheBenchmarks | ||
| package.targets += [ | ||
| .executableTarget( | ||
|   | ||
| name: "MemcacheBenchmarks", | ||
| dependencies: [ | ||
| .product(name: "Memcache", package: "swift-memcache-gsoc"), | ||
| .product(name: "Benchmark", package: "package-benchmark"), | ||
| .product(name: "NIOCore", package: "swift-nio"), | ||
| .product(name: "NIOPosix", package: "swift-nio"), | ||
| ], | ||
| path: "Benchmarks/MemcacheBenchmarks", | ||
| plugins: [ | ||
| .plugin(name: "BenchmarkPlugin", package: "package-benchmark"), | ||
| ] | ||
| ), | ||
| ] | ||
|   | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the swift-memcache-gsoc open source project | ||
| // | ||
| // Copyright (c) 2023 Apple Inc. and the swift-memcache-gsoc project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of swift-memcache-gsoc project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | 
|   | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the swift-memcache-gsoc open source project | ||
| // | ||
| // Copyright (c) 2023 Apple Inc. and the swift-memcache-gsoc project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of swift-memcache-gsoc project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|  | ||
| @testable import Benchmarks | ||
| import XCTest | ||
|  | ||
| final class BenchmarksTests: XCTestCase { | ||
| func testExample() throws { | ||
| // XCTest Documentation | ||
| // https://developer.apple.com/documentation/xctest | ||
|  | ||
| // Defining Test Cases and Test Methods | ||
| // https://developer.apple.com/documentation/xctest/defining_test_cases_and_test_methods | ||
| } | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 148242431, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 68, | ||
| "memoryLeaked" : 516351 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 162267135, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 64, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 147849215, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 69, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 160432127, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 69, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 165019647, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 75, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 141950975, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 65, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 161480703, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 62, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 149422079, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 64, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 170393599, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 62, | ||
| "memoryLeaked" : 520447 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 167772159, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 63, | ||
| "memoryLeaked" : 520447 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 149159935, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 73, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 169476095, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 62, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 152436735, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 86, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 162660351, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 71, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 168296447, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 64, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 147062783, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 73, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 167772159, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 65, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 147849215, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 84, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 161742847, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 74, | ||
| "memoryLeaked" : 528895 | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "allocatedResidentMemory" : 166330367, | ||
| "mallocCountLarge" : 3, | ||
| "mallocCountTotal" : 66, | ||
| "memoryLeaked" : 528895 | ||
| } | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for now only
mallocCountTotalis fine