|
2 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
|
5 | | -use std::env; |
| 5 | +use std::sync::Arc; |
6 | 6 | use std::time::Duration; |
7 | 7 |
|
8 | 8 | mod cli; |
9 | 9 | pub use cli::Args; |
10 | 10 |
|
| 11 | +#[derive(uniffi::Record)] |
11 | 12 | pub struct TestData { |
12 | 13 | foo: String, |
13 | 14 | bar: String, |
14 | 15 | } |
15 | 16 |
|
| 17 | +#[derive(uniffi::Enum)] |
16 | 18 | pub enum TestCase { |
17 | 19 | Function, |
18 | 20 | VoidReturn, |
19 | 21 | NoArgsVoidReturn, |
20 | 22 | } |
21 | 23 |
|
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 { |
23 | 31 | fn method(&self, a: i32, b: i32, data: TestData) -> String; |
24 | 32 | fn method_with_void_return(&self, a: i32, b: i32, data: TestData); |
25 | 33 | fn method_with_no_args_and_void_return(&self); |
| 34 | + /// Run a performance test N times and return the elapsed time in nanoseconds |
26 | 35 | fn run_test(&self, test_case: TestCase, count: u64) -> u64; |
27 | 36 | } |
28 | 37 |
|
| 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] |
29 | 44 | pub fn test_function(_a: i32, _b: i32, data: TestData) -> String { |
30 | 45 | data.bar |
31 | 46 | } |
| 47 | + |
| 48 | +#[uniffi::export] |
32 | 49 | pub fn test_void_return(_a: i32, _b: i32, _data: TestData) {} |
| 50 | +#[uniffi::export] |
33 | 51 | pub fn test_no_args_void_return() {} |
34 | 52 |
|
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>) { |
36 | 56 | let args = Args::parse_for_run_benchmarks(); |
37 | 57 | let mut c = args.build_criterion(); |
38 | 58 |
|
@@ -90,4 +110,4 @@ pub fn run_benchmarks(language: String, cb: Box<dyn TestCallbackInterface>) { |
90 | 110 | c.final_summary(); |
91 | 111 | } |
92 | 112 |
|
93 | | -uniffi::include_scaffolding!("benchmarks"); |
| 113 | +uniffi::setup_scaffolding!("benchmarks"); |
0 commit comments