Skip to content

Commit 21ffde9

Browse files
authored
Tweaks to benchmarks: update docs, remove UDL, Python was stale. (#2668)
1 parent 50e1e61 commit 21ffde9

File tree

6 files changed

+28
-56
lines changed

6 files changed

+28
-56
lines changed

fixtures/benchmarks/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ uniffi = { workspace = true }
1515
clap = { version = "4", features = ["cargo", "std", "derive"] }
1616
criterion = "0.5.1"
1717

18-
[build-dependencies]
19-
uniffi = { workspace = true, features = ["build"] }
20-
2118
[dev-dependencies]
2219
uniffi_bindgen = {path = "../../uniffi_bindgen", features = ["bindgen-tests"]}
2320

fixtures/benchmarks/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
This fixture runs a set of benchmark tests, using criterion to test the performance.
22

3+
Note your cwd must be this crate, not the workspace/repo root!
4+
35
- `cargo bench` to run all benchmarks.
46
- `cargo bench -- -p` to run all python benchmarks (or -s for swift, -k for kotlin)
57
- `cargo bench -- [glob]` to run a subset of the benchmarks

fixtures/benchmarks/benches/bindings/run_benchmarks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from benchmarks import *
66
import time
77

8-
class TestCallbackObj:
8+
class TestCallbackObj(TestCallbackInterface):
99
def method(self, a, b, data):
1010
return data.bar
1111

@@ -16,7 +16,7 @@ def method_with_no_args_and_void_return(self):
1616
pass
1717

1818
def run_test(self, test_case, count):
19-
data = TestData("StringOne", "StringTwo")
19+
data = TestData(foo="StringOne", bar="StringTwo")
2020
if test_case == TestCase.FUNCTION:
2121
start = time.perf_counter_ns()
2222
for i in range(count):

fixtures/benchmarks/build.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

fixtures/benchmarks/src/benchmarks.udl

Lines changed: 0 additions & 40 deletions
This file was deleted.

fixtures/benchmarks/src/lib.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,57 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use std::env;
5+
use std::sync::Arc;
66
use std::time::Duration;
77

88
mod cli;
99
pub use cli::Args;
1010

11+
#[derive(uniffi::Record)]
1112
pub struct TestData {
1213
foo: String,
1314
bar: String,
1415
}
1516

17+
#[derive(uniffi::Enum)]
1618
pub enum TestCase {
1719
Function,
1820
VoidReturn,
1921
NoArgsVoidReturn,
2022
}
2123

22-
pub trait TestCallbackInterface {
24+
/// Test callback methods.
25+
///
26+
/// These are intended to test the overhead of callback interface calls
27+
/// including: popping arguments from the stack, unpacking RustBuffers,
28+
/// pushing return values back to the stack, etc.
29+
#[uniffi::export(with_foreign)]
30+
pub trait TestCallbackInterface: Send + Sync {
2331
fn method(&self, a: i32, b: i32, data: TestData) -> String;
2432
fn method_with_void_return(&self, a: i32, b: i32, data: TestData);
2533
fn method_with_no_args_and_void_return(&self);
34+
/// Run a performance test N times and return the elapsed time in nanoseconds
2635
fn run_test(&self, test_case: TestCase, count: u64) -> u64;
2736
}
2837

38+
/// Test functions
39+
///
40+
/// These are intended to test the overhead of Rust function calls including:
41+
/// popping arguments from the stack, unpacking RustBuffers, pushing return
42+
/// values back to the stack, etc.
43+
#[uniffi::export]
2944
pub fn test_function(_a: i32, _b: i32, data: TestData) -> String {
3045
data.bar
3146
}
47+
48+
#[uniffi::export]
3249
pub fn test_void_return(_a: i32, _b: i32, _data: TestData) {}
50+
#[uniffi::export]
3351
pub fn test_no_args_void_return() {}
3452

35-
pub fn run_benchmarks(language: String, cb: Box<dyn TestCallbackInterface>) {
53+
/// Run all benchmarks and print the results to stdout
54+
#[uniffi::export]
55+
pub fn run_benchmarks(language: String, cb: Arc<dyn TestCallbackInterface>) {
3656
let args = Args::parse_for_run_benchmarks();
3757
let mut c = args.build_criterion();
3858

@@ -90,4 +110,4 @@ pub fn run_benchmarks(language: String, cb: Box<dyn TestCallbackInterface>) {
90110
c.final_summary();
91111
}
92112

93-
uniffi::include_scaffolding!("benchmarks");
113+
uniffi::setup_scaffolding!("benchmarks");

0 commit comments

Comments
 (0)