-
Notifications
You must be signed in to change notification settings - Fork 48
Add placeholder ordo-benchmark and JMH benchmarks #134
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2d7c2c3
Add placeholder ordo-benchmark and JMH benchmarks
helmetcrest a96d077
Fix build error
helmetcrest 0a1b742
add benchmarking readme
ktoso 1d231bc
Include benchmarks in PR validation: both JMH and Swift
ktoso 80f91a0
disable Swift benchmark building in CI
ktoso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
34 changes: 34 additions & 0 deletions
34
Benchmarks/Benchmarks/JavaApiCallBenchmarks/JavaApiCallBenchmarks.swift
This file contains hidden or 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,34 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the Swift.org project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of Swift.org project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Benchmark | ||
import Foundation | ||
import JavaKit | ||
import JavaKitNetwork | ||
|
||
@MainActor let benchmarks = { | ||
var jvm: JavaVirtualMachine { | ||
get throws { | ||
try .shared() | ||
} | ||
} | ||
Benchmark("Simple call to Java library") { benchmark in | ||
for _ in benchmark.scaledIterations { | ||
let environment = try jvm.environment() | ||
|
||
let urlConnectionClass = try JavaClass<URLConnection>(environment: environment) | ||
blackHole(urlConnectionClass.getDefaultAllowUserInteraction()) | ||
} | ||
} | ||
} |
This file contains hidden or 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,69 @@ | ||
// swift-tools-version: 6.0 | ||
|
||
import PackageDescription | ||
|
||
import class Foundation.FileManager | ||
import class Foundation.ProcessInfo | ||
|
||
// Note: the JAVA_HOME environment variable must be set to point to where | ||
ktoso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Java is installed, e.g., | ||
// Library/Java/JavaVirtualMachines/openjdk-21.jdk/Contents/Home. | ||
func findJavaHome() -> String { | ||
if let home = ProcessInfo.processInfo.environment["JAVA_HOME"] { | ||
return home | ||
} | ||
|
||
// This is a workaround for envs (some IDEs) which have trouble with | ||
// picking up env variables during the build process | ||
let path = "\(FileManager.default.homeDirectoryForCurrentUser.path()).java_home" | ||
if let home = try? String(contentsOfFile: path, encoding: .utf8) { | ||
if let lastChar = home.last, lastChar.isNewline { | ||
return String(home.dropLast()) | ||
} | ||
|
||
return home | ||
} | ||
|
||
fatalError("Please set the JAVA_HOME environment variable to point to where Java is installed.") | ||
} | ||
let javaHome = findJavaHome() | ||
|
||
let javaIncludePath = "\(javaHome)/include" | ||
#if os(Linux) | ||
let javaPlatformIncludePath = "\(javaIncludePath)/linux" | ||
#elseif os(macOS) | ||
let javaPlatformIncludePath = "\(javaIncludePath)/darwin" | ||
#else | ||
// TODO: Handle windows as well | ||
#error("Currently only macOS and Linux platforms are supported, this may change in the future.") | ||
#endif | ||
|
||
let package = Package( | ||
name: "benchmarks", | ||
platforms: [ | ||
.macOS("15.03") | ||
], | ||
dependencies: [ | ||
.package(path: "../"), | ||
.package(url: "https://github.com/ordo-one/package-benchmark", .upToNextMajor(from: "1.4.0")), | ||
], | ||
targets: [ | ||
.executableTarget( | ||
name: "JavaApiCallBenchmarks", | ||
dependencies: [ | ||
.product(name: "JavaRuntime", package: "swift-java"), | ||
.product(name: "JavaKit", package: "swift-java"), | ||
.product(name: "JavaKitNetwork", package: "swift-java"), | ||
.product(name: "Benchmark", package: "package-benchmark"), | ||
], | ||
path: "Benchmarks/JavaApiCallBenchmarks", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool structure is looking good now |
||
swiftSettings: [ | ||
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]), | ||
.swiftLanguageMode(.v5), | ||
], | ||
plugins: [ | ||
.plugin(name: "BenchmarkPlugin", package: "package-benchmark") | ||
] | ||
) | ||
] | ||
) |
This file contains hidden or 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 |
---|---|---|
|
@@ -133,12 +133,12 @@ jextract-generate: jextract-swift generate-JExtract-interface-files | |
swift run jextract-swift \ | ||
--package-name com.example.swift.generated \ | ||
--swift-module ExampleSwiftLibrary \ | ||
--output-directory ${SAMPLES_DIR}/SwiftKitSampleApp/src/generated/java \ | ||
--output-directory ${SAMPLES_DIR}/SwiftKitSampleApp/build/generated/sources/jextract/main \ | ||
$(BUILD_DIR)/jextract/ExampleSwiftLibrary/MySwiftLibrary.swiftinterface; \ | ||
swift run jextract-swift \ | ||
--package-name org.swift.swiftkit.generated \ | ||
--swift-module SwiftKitSwift \ | ||
--output-directory ${SAMPLES_DIR}/SwiftKitSampleApp/src/generated/java \ | ||
--output-directory ${SAMPLES_DIR}/SwiftKitSampleApp/build/generated/sources/jextract/main \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense! |
||
$(BUILD_DIR)/jextract/SwiftKitSwift/SwiftKit.swiftinterface | ||
|
||
|
||
|
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.