benchset 0.0.6__tar.gz → 0.0.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {benchset-0.0.6 → benchset-0.0.8}/Cargo.lock +1 -1
- {benchset-0.0.6 → benchset-0.0.8}/Cargo.toml +2 -1
- {benchset-0.0.6 → benchset-0.0.8}/MANIFEST.in +1 -0
- {benchset-0.0.6 → benchset-0.0.8}/PKG-INFO +55 -5
- {benchset-0.0.6 → benchset-0.0.8}/Package.swift +2 -2
- {benchset-0.0.6 → benchset-0.0.8}/README.md +54 -4
- {benchset-0.0.6 → benchset-0.0.8}/Sources/Benchset/Benchset.swift +153 -88
- benchset-0.0.8/benchset/_aggregate.py +81 -0
- benchset-0.0.8/benchset/_metadata.json +1 -0
- benchset-0.0.8/benchset/_metadata.py +52 -0
- benchset-0.0.8/benchset/_native.py +588 -0
- benchset-0.0.8/benchset/api.py +247 -0
- benchset-0.0.8/benchset/cli.py +417 -0
- {benchset-0.0.6 → benchset-0.0.8}/benchset/models.py +10 -21
- {benchset-0.0.6 → benchset-0.0.8}/benchset/reference.py +7 -19
- {benchset-0.0.6 → benchset-0.0.8}/benchset.egg-info/PKG-INFO +55 -5
- {benchset-0.0.6 → benchset-0.0.8}/benchset.egg-info/SOURCES.txt +51 -0
- {benchset-0.0.6 → benchset-0.0.8}/include/benchset.h +67 -0
- benchset-0.0.8/native/build.rs +69 -0
- benchset-0.0.8/native/src/aggregate_protocol_tests.rs +545 -0
- benchset-0.0.8/native/src/aggregation_ffi.rs +173 -0
- benchset-0.0.8/native/src/aggregation_ffi_tests.rs +279 -0
- benchset-0.0.8/native/src/catalog.rs +33 -0
- benchset-0.0.8/native/src/config_ffi.rs +79 -0
- benchset-0.0.8/native/src/config_ffi_tests.rs +296 -0
- benchset-0.0.8/native/src/configured_suite_tests.rs +350 -0
- {benchset-0.0.6 → benchset-0.0.8}/native/src/ffi.rs +34 -7
- {benchset-0.0.6 → benchset-0.0.8}/native/src/ffi_tests.rs +92 -0
- {benchset-0.0.6 → benchset-0.0.8}/native/src/lib.rs +110 -43
- benchset-0.0.8/native/src/observed_suite_tests.rs +179 -0
- {benchset-0.0.6 → benchset-0.0.8}/native/src/suite_ffi.rs +81 -10
- {benchset-0.0.6 → benchset-0.0.8}/native/src/suite_tests.rs +76 -0
- {benchset-0.0.6 → benchset-0.0.8}/pyproject.toml +3 -3
- benchset-0.0.8/scripts/build_native.py +19 -0
- benchset-0.0.8/scripts/cargo.py +111 -0
- {benchset-0.0.6 → benchset-0.0.8}/scripts/check_source_install.py +2 -1
- {benchset-0.0.6 → benchset-0.0.8}/setup.py +43 -14
- benchset-0.0.8/tests/helpers.py +68 -0
- benchset-0.0.8/tests/swift/AggregationTests.swift +25 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/swift/BenchsetTests.swift +252 -21
- benchset-0.0.8/tests/test_aggregate_exponential.py +278 -0
- benchset-0.0.8/tests/test_aggregate_getters.py +151 -0
- benchset-0.0.8/tests/test_aggregate_memory.py +51 -0
- benchset-0.0.8/tests/test_aggregate_protocols.py +321 -0
- benchset-0.0.8/tests/test_aggregate_tuple_inputs.py +116 -0
- benchset-0.0.8/tests/test_aggregation_boundary.py +161 -0
- benchset-0.0.8/tests/test_approved_python_contracts.py +311 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_build_native.py +11 -3
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_cli.py +261 -1
- benchset-0.0.8/tests/test_cli_active_signal_policy.py +140 -0
- benchset-0.0.8/tests/test_cli_cleanup_signals.py +328 -0
- benchset-0.0.8/tests/test_cli_embedded_signals.py +269 -0
- benchset-0.0.8/tests/test_cli_final_signal_restore.py +191 -0
- benchset-0.0.8/tests/test_cli_loader_validation.py +88 -0
- benchset-0.0.8/tests/test_cli_loading_signals.py +351 -0
- benchset-0.0.8/tests/test_cli_observer_signals.py +111 -0
- benchset-0.0.8/tests/test_cli_progress_streams.py +217 -0
- benchset-0.0.8/tests/test_cli_signal_policy.py +144 -0
- benchset-0.0.8/tests/test_cli_terminal_errors.py +134 -0
- benchset-0.0.8/tests/test_core_contract.py +45 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_errors.py +50 -12
- benchset-0.0.8/tests/test_exception_contexts.py +180 -0
- benchset-0.0.8/tests/test_float_transport.py +141 -0
- benchset-0.0.8/tests/test_installer_copy.py +379 -0
- benchset-0.0.8/tests/test_interpreter_boundary.py +241 -0
- benchset-0.0.8/tests/test_loader_failures.py +391 -0
- benchset-0.0.8/tests/test_loader_imports.py +123 -0
- benchset-0.0.8/tests/test_loader_signals.py +497 -0
- benchset-0.0.8/tests/test_metadata.py +537 -0
- benchset-0.0.8/tests/test_name_diagnostics.py +106 -0
- benchset-0.0.8/tests/test_name_operands.py +181 -0
- benchset-0.0.8/tests/test_native_lifetimes.py +286 -0
- benchset-0.0.8/tests/test_publication.py +283 -0
- benchset-0.0.8/tests/test_publication_signals.py +576 -0
- benchset-0.0.8/tests/test_python_core.py +653 -0
- benchset-0.0.8/tests/test_quiet_validation.py +457 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_reference.py +6 -2
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_reference_artifacts.py +17 -2
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_release.py +2 -1
- benchset-0.0.8/tests/test_resources.py +329 -0
- benchset-0.0.8/tests/test_runner_thread_safety.py +201 -0
- benchset-0.0.8/tests/test_rust_api.py +102 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_semantics.py +53 -15
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_setup.py +55 -3
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_signals.py +72 -12
- benchset-0.0.8/tests/test_suite.py +375 -0
- benchset-0.0.8/tests/test_suite_options.py +456 -0
- benchset-0.0.8/tests/test_suite_signal_policy.py +297 -0
- benchset-0.0.8/tests/test_validation_lifetime.py +307 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/typing/reference_positive.py +3 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/typing/test_reference_types.py +9 -5
- benchset-0.0.6/benchset/_native.py +0 -266
- benchset-0.0.6/benchset/api.py +0 -165
- benchset-0.0.6/benchset/cli.py +0 -283
- benchset-0.0.6/scripts/build_native.py +0 -29
- benchset-0.0.6/scripts/cargo.py +0 -11
- benchset-0.0.6/tests/helpers.py +0 -35
- benchset-0.0.6/tests/test_resources.py +0 -118
- benchset-0.0.6/tests/test_suite.py +0 -179
- {benchset-0.0.6 → benchset-0.0.8}/LICENSE +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/benchset/__init__.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/benchset/__main__.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/benchset/py.typed +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/benchset.egg-info/dependency_links.txt +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/benchset.egg-info/entry_points.txt +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/benchset.egg-info/requires.txt +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/benchset.egg-info/top_level.txt +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/examples/native/c.c +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/examples/native/rust.rs +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/examples/native/swift.swift +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/include/module.modulemap +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/native/reference-calibration.json +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/native/src/ffi_reference_tests.rs +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/native/src/kernel.rs +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/native/src/kernel_tests.rs +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/native/src/reference.rs +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/native/src/reference_tests.rs +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/native/src/runtime_tests.rs +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/native/src/suite_ffi_tests.rs +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/rust-toolchain.toml +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/scripts/__init__.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/scripts/build_backend.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/scripts/check_native_coverage.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/scripts/package_native.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/scripts/release.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/scripts/version.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/setup.cfg +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/__init__.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/swift/ReferenceTests.swift +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_benchset.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_build.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_native_coverage.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_packaging.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_reference_native.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/test_version.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/typing/__init__.py +0 -0
- {benchset-0.0.6 → benchset-0.0.8}/tests/typing/reference_negative.py +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "benchset"
|
|
3
3
|
# Generated from [project].version in pyproject.toml by scripts/version.py.
|
|
4
|
-
version = "0.0.
|
|
4
|
+
version = "0.0.8"
|
|
5
5
|
edition = "2021"
|
|
6
6
|
rust-version = "1.74"
|
|
7
|
+
build = "native/build.rs"
|
|
7
8
|
description = "Embeddable sustained scalar CPU benchmarks with a C ABI"
|
|
8
9
|
license = "MIT"
|
|
9
10
|
repository = "https://github.com/mutating/benchset"
|
|
@@ -2,6 +2,7 @@ include setup.py
|
|
|
2
2
|
include Cargo.toml Cargo.lock rust-toolchain.toml LICENSE README.md
|
|
3
3
|
recursive-include native *.rs
|
|
4
4
|
include native/reference-calibration.json
|
|
5
|
+
include benchset/_metadata.json
|
|
5
6
|
recursive-include include *.h *.modulemap
|
|
6
7
|
recursive-include scripts *.py
|
|
7
8
|
recursive-include examples *.c *.rs *.swift
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: benchset
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.8
|
|
4
4
|
Summary: Sustained scalar CPU benchmarks with an embeddable Rust core
|
|
5
5
|
Author-email: Evgeniy Blinov <zheni-b@yandex.ru>
|
|
6
6
|
Project-URL: Source, https://github.com/mutating/benchset
|
|
@@ -38,6 +38,18 @@ Sustained scalar CPU throughput, with an embeddable Rust core, a public C ABI,
|
|
|
38
38
|
a Python library, a CLI, and a macOS Swift package. No Python interpreter is
|
|
39
39
|
needed by applications embedding the native library.
|
|
40
40
|
|
|
41
|
+
Rust is the single source of benchmark behavior: workloads, timing, validation,
|
|
42
|
+
suite order and early stopping, scores and aggregation all live in the native
|
|
43
|
+
core. Python and Swift are thin bindings to its C ABI. They handle language
|
|
44
|
+
types, callbacks, signals and native-handle lifetimes without reimplementing
|
|
45
|
+
benchmark rules. The C ABI supports both static and dynamic linking.
|
|
46
|
+
|
|
47
|
+
Benchmark identities, default durations and calibration are also defined in
|
|
48
|
+
Rust. Native builds generate the Python package's `_metadata.json` from those
|
|
49
|
+
definitions; it is a generated data snapshot, not a second implementation.
|
|
50
|
+
This keeps imports, metadata inspection and CLI help available without loading
|
|
51
|
+
the native library. Update Rust sources rather than editing that snapshot.
|
|
52
|
+
|
|
41
53
|
The initial suite contains **`single_core`** (one computational worker) and
|
|
42
54
|
**`multi_core`** (all available computational workers). Both execute the same
|
|
43
55
|
fixed mixed workload and return a score in **completed iterations per second**.
|
|
@@ -96,6 +108,9 @@ Completed result fields, including all measurement samples, are printed to
|
|
|
96
108
|
stdout. Failed/cancelled results go to stderr. Exit codes: 0 completed, 1
|
|
97
109
|
execution failure, 2 invalid CLI arguments, 130 interrupted/cancelled. The
|
|
98
110
|
suite stops after a failed or cancelled benchmark.
|
|
111
|
+
Duration validation loads the Rust library. If loading fails, that error takes
|
|
112
|
+
precedence over invalid duration values and the CLI exits with code 1.
|
|
113
|
+
Argument syntax, `--help` and `--version` do not require loading the library.
|
|
99
114
|
Each result is flushed immediately, including when stdout is redirected.
|
|
100
115
|
Progress fits the terminal width and is cleared before the result. Output
|
|
101
116
|
uses `× pi` and `—` when the stream supports them, with `x pi` and `-` as
|
|
@@ -136,7 +151,7 @@ With the current two benchmarks this is mathematically
|
|
|
136
151
|
independently of its worker count or measurement duration. The resulting
|
|
137
152
|
multiplier is dimensionless; individual `score` fields remain iterations/s.
|
|
138
153
|
|
|
139
|
-
The
|
|
154
|
+
The Rust core uses natural logarithms and `exp` on the original,
|
|
140
155
|
unrounded double-precision ratios. Log space avoids intermediate overflow or
|
|
141
156
|
underflow from multiplying ratios. Any consistent logarithm base and its
|
|
142
157
|
inverse give the same mathematical result; ordinary floating-point rounding
|
|
@@ -152,6 +167,10 @@ A full score requires exactly `single_core` then `multi_core`, both with
|
|
|
152
167
|
unstable results participate. After validating the complete set, any zero ratio
|
|
153
168
|
makes the full score `0.0`. Zero is a valid score: check `is not None` in Python,
|
|
154
169
|
`Some` in Rust, `if let` in Swift, or the presence flag in C.
|
|
170
|
+
Native numeric validation rejects NaN and infinities without adding floating-point
|
|
171
|
+
exception flags; flags already set by the caller are preserved. Native validation
|
|
172
|
+
classifies the stored numeric value even when the FPU flushes subnormal numbers
|
|
173
|
+
to zero; this also applies to duration validation in every language.
|
|
155
174
|
|
|
156
175
|
An incomplete, failed or cancelled suite has no aggregate: `None` in
|
|
157
176
|
Python/Rust, `nil` in Swift, or a zero presence flag in C. When a benchmark
|
|
@@ -161,6 +180,7 @@ complete order, without duplicates or
|
|
|
161
180
|
extra entries. Use `SuiteResult.from_results(tuple_of_results)` in Python,
|
|
162
181
|
`SuiteResult::new(results)` in Rust, or `SuiteResult(results: results)` in Swift
|
|
163
182
|
to calculate the aggregate from their stored individual Pi equivalents.
|
|
183
|
+
The Python and Swift factories call the same Rust calculator through the C ABI.
|
|
164
184
|
Python's direct `SuiteResult(results, aggregated_scores)` constructor stores
|
|
165
185
|
the supplied fields; it does not calculate an aggregate.
|
|
166
186
|
|
|
@@ -175,6 +195,24 @@ restart for the next benchmark.
|
|
|
175
195
|
|
|
176
196
|
Python 3.8–3.15, including free-threaded CPython, is supported. The wrapper uses
|
|
177
197
|
standard-library `ctypes` and loads the version-matched bundled native library.
|
|
198
|
+
`run`, `run_all` and `SuiteResult.from_results` require that native library,
|
|
199
|
+
including when inputs are invalid or an aggregate is unavailable. A library
|
|
200
|
+
loading or compatibility error takes precedence over benchmark argument
|
|
201
|
+
validation. Argument checks and their diagnostics are supplied by Rust;
|
|
202
|
+
Python still performs its ordinary numeric type conversions at the boundary.
|
|
203
|
+
Integer subclass ratios are calculated from their `float(...)` conversions;
|
|
204
|
+
Python aggregation retains Python comparisons, including their behavior under
|
|
205
|
+
the caller's FPU mode and subclass overrides. Each requested `result.success`
|
|
206
|
+
value is converted to `bool` once. When aggregating a tuple subclass,
|
|
207
|
+
the factory uses its actual stored elements and length, retaining the original
|
|
208
|
+
tuple in `suite.results`.
|
|
209
|
+
|
|
210
|
+
Benchmark names must be strings. A name subclass may customize an unknown-name
|
|
211
|
+
diagnostic through Python's string operators; its result must also be a string,
|
|
212
|
+
otherwise `TypeError` is raised before any benchmark starts. Compatibility
|
|
213
|
+
covers the documented public API, not incidental dependency names imported by
|
|
214
|
+
internal modules or the exact time temporary Python objects are finalized.
|
|
215
|
+
The CLI does not guarantee context-variable inheritance by its internal threads.
|
|
178
216
|
|
|
179
217
|
```python
|
|
180
218
|
from benchset import run, run_all
|
|
@@ -407,6 +445,8 @@ Swift uses camelCase fields, such as `shortName`, `startedAtUnixSeconds` and
|
|
|
407
445
|
`started_at` datetime; Swift offers `startedAt: Date` for the same instant.
|
|
408
446
|
The frozen Python records use a tuple for results; Swift returns immutable
|
|
409
447
|
value snapshots. Reading the Python globals does not load the native library.
|
|
448
|
+
Their values come from the Rust-generated snapshot bundled with the package;
|
|
449
|
+
builds refresh it from the same sources used to compile the native library.
|
|
410
450
|
|
|
411
451
|
[Calibration values and provenance](native/reference-calibration.json) include
|
|
412
452
|
the original kernel commit, binary SHA-256, raw pooled totals and series
|
|
@@ -436,7 +476,7 @@ pinned release toolchain described under [Publishing](#publishing).
|
|
|
436
476
|
|
|
437
477
|
```toml
|
|
438
478
|
[dependencies]
|
|
439
|
-
benchset = "0.0.
|
|
479
|
+
benchset = "0.0.8"
|
|
440
480
|
# For changes from a local source checkout, use:
|
|
441
481
|
# benchset = { path = "../benchset" }
|
|
442
482
|
```
|
|
@@ -529,6 +569,12 @@ Check `suite.aggregated_scores.has_pi_equivalent` before reading its
|
|
|
529
569
|
`benchset_suite_reason`. Use `benchset_suite_cancel` and `benchset_suite_free`
|
|
530
570
|
for cancellation and cleanup. The same single-use and lifetime rules apply.
|
|
531
571
|
|
|
572
|
+
`benchset_run_all_observed` additionally accepts a result callback for streaming
|
|
573
|
+
each result before the next benchmark starts. Its child handle is borrowed only
|
|
574
|
+
during that callback; copy diagnostics through the single-benchmark getters.
|
|
575
|
+
Returning any nonzero value stops further benchmarks. Python and Swift bindings
|
|
576
|
+
use this entry point; suite ordering and stopping remain in Rust.
|
|
577
|
+
|
|
532
578
|
For example, using the initialized `config` above and no progress callback:
|
|
533
579
|
|
|
534
580
|
```c
|
|
@@ -596,7 +642,7 @@ the same repository. Rust is not required by the consumer.
|
|
|
596
642
|
For a Swift manifest, add:
|
|
597
643
|
|
|
598
644
|
```swift
|
|
599
|
-
.package(url: "https://github.com/mutating/benchset.git", .exact("0.0.
|
|
645
|
+
.package(url: "https://github.com/mutating/benchset.git", .exact("0.0.8"))
|
|
600
646
|
```
|
|
601
647
|
|
|
602
648
|
Add `.product(name: "Benchset", package: "benchset")` to your target's
|
|
@@ -635,7 +681,9 @@ if let fullPi = suite.aggregatedScores.piEquivalent {
|
|
|
635
681
|
```
|
|
636
682
|
|
|
637
683
|
`runAll` keeps the runner reserved across both benchmarks; cancellation also
|
|
638
|
-
applies between
|
|
684
|
+
applies between benchmarks through the native suite's cancellation token.
|
|
685
|
+
Both Swift `runAll` and Python `run_all` call the Rust suite runner through C.
|
|
686
|
+
Native failure/cancellation returns the
|
|
639
687
|
results obtained so far with a `nil` aggregate. Wrapper errors such as allocation
|
|
640
688
|
failure or an unavailable native result throw `BenchsetError`; that call returns
|
|
641
689
|
no `SuiteResult`.
|
|
@@ -711,6 +759,8 @@ controlled initialization failures instead of exhausting machine resources.
|
|
|
711
759
|
Full-suite tests also cover complete ordering, geometric means of unrounded
|
|
712
760
|
ratios, zero/invalid/extreme values, early stopping, serialization and the
|
|
713
761
|
aggregate's presence in each public interface.
|
|
762
|
+
The [core centralization regression matrix](tests/core-centralization-plan.md)
|
|
763
|
+
maps the shared-core contracts to characterization tests and directed mutations.
|
|
714
764
|
|
|
715
765
|
Python coverage includes statements and branches, including CLI subprocesses;
|
|
716
766
|
CI installs a coverage startup hook for those subprocesses. Rust and Swift each
|
|
@@ -9,8 +9,8 @@ let package = Package(
|
|
|
9
9
|
products: [.library(name: "Benchset", targets: ["Benchset"])],
|
|
10
10
|
targets: [
|
|
11
11
|
.binaryTarget(name: "CBenchset",
|
|
12
|
-
url: "https://github.com/mutating/benchset/releases/download/v0.0.
|
|
13
|
-
checksum: "
|
|
12
|
+
url: "https://github.com/mutating/benchset/releases/download/v0.0.8/Benchset.xcframework.zip",
|
|
13
|
+
checksum: "dbac0aa83bcb256b908a9ddf040324d0f675fb1da5e073b5f11b3bc06723f3eb"),
|
|
14
14
|
.target(name: "Benchset", dependencies: ["CBenchset"]),
|
|
15
15
|
.testTarget(name: "BenchsetTests", dependencies: ["Benchset"], path: "tests/swift")
|
|
16
16
|
]
|
|
@@ -4,6 +4,18 @@ Sustained scalar CPU throughput, with an embeddable Rust core, a public C ABI,
|
|
|
4
4
|
a Python library, a CLI, and a macOS Swift package. No Python interpreter is
|
|
5
5
|
needed by applications embedding the native library.
|
|
6
6
|
|
|
7
|
+
Rust is the single source of benchmark behavior: workloads, timing, validation,
|
|
8
|
+
suite order and early stopping, scores and aggregation all live in the native
|
|
9
|
+
core. Python and Swift are thin bindings to its C ABI. They handle language
|
|
10
|
+
types, callbacks, signals and native-handle lifetimes without reimplementing
|
|
11
|
+
benchmark rules. The C ABI supports both static and dynamic linking.
|
|
12
|
+
|
|
13
|
+
Benchmark identities, default durations and calibration are also defined in
|
|
14
|
+
Rust. Native builds generate the Python package's `_metadata.json` from those
|
|
15
|
+
definitions; it is a generated data snapshot, not a second implementation.
|
|
16
|
+
This keeps imports, metadata inspection and CLI help available without loading
|
|
17
|
+
the native library. Update Rust sources rather than editing that snapshot.
|
|
18
|
+
|
|
7
19
|
The initial suite contains **`single_core`** (one computational worker) and
|
|
8
20
|
**`multi_core`** (all available computational workers). Both execute the same
|
|
9
21
|
fixed mixed workload and return a score in **completed iterations per second**.
|
|
@@ -62,6 +74,9 @@ Completed result fields, including all measurement samples, are printed to
|
|
|
62
74
|
stdout. Failed/cancelled results go to stderr. Exit codes: 0 completed, 1
|
|
63
75
|
execution failure, 2 invalid CLI arguments, 130 interrupted/cancelled. The
|
|
64
76
|
suite stops after a failed or cancelled benchmark.
|
|
77
|
+
Duration validation loads the Rust library. If loading fails, that error takes
|
|
78
|
+
precedence over invalid duration values and the CLI exits with code 1.
|
|
79
|
+
Argument syntax, `--help` and `--version` do not require loading the library.
|
|
65
80
|
Each result is flushed immediately, including when stdout is redirected.
|
|
66
81
|
Progress fits the terminal width and is cleared before the result. Output
|
|
67
82
|
uses `× pi` and `—` when the stream supports them, with `x pi` and `-` as
|
|
@@ -102,7 +117,7 @@ With the current two benchmarks this is mathematically
|
|
|
102
117
|
independently of its worker count or measurement duration. The resulting
|
|
103
118
|
multiplier is dimensionless; individual `score` fields remain iterations/s.
|
|
104
119
|
|
|
105
|
-
The
|
|
120
|
+
The Rust core uses natural logarithms and `exp` on the original,
|
|
106
121
|
unrounded double-precision ratios. Log space avoids intermediate overflow or
|
|
107
122
|
underflow from multiplying ratios. Any consistent logarithm base and its
|
|
108
123
|
inverse give the same mathematical result; ordinary floating-point rounding
|
|
@@ -118,6 +133,10 @@ A full score requires exactly `single_core` then `multi_core`, both with
|
|
|
118
133
|
unstable results participate. After validating the complete set, any zero ratio
|
|
119
134
|
makes the full score `0.0`. Zero is a valid score: check `is not None` in Python,
|
|
120
135
|
`Some` in Rust, `if let` in Swift, or the presence flag in C.
|
|
136
|
+
Native numeric validation rejects NaN and infinities without adding floating-point
|
|
137
|
+
exception flags; flags already set by the caller are preserved. Native validation
|
|
138
|
+
classifies the stored numeric value even when the FPU flushes subnormal numbers
|
|
139
|
+
to zero; this also applies to duration validation in every language.
|
|
121
140
|
|
|
122
141
|
An incomplete, failed or cancelled suite has no aggregate: `None` in
|
|
123
142
|
Python/Rust, `nil` in Swift, or a zero presence flag in C. When a benchmark
|
|
@@ -127,6 +146,7 @@ complete order, without duplicates or
|
|
|
127
146
|
extra entries. Use `SuiteResult.from_results(tuple_of_results)` in Python,
|
|
128
147
|
`SuiteResult::new(results)` in Rust, or `SuiteResult(results: results)` in Swift
|
|
129
148
|
to calculate the aggregate from their stored individual Pi equivalents.
|
|
149
|
+
The Python and Swift factories call the same Rust calculator through the C ABI.
|
|
130
150
|
Python's direct `SuiteResult(results, aggregated_scores)` constructor stores
|
|
131
151
|
the supplied fields; it does not calculate an aggregate.
|
|
132
152
|
|
|
@@ -141,6 +161,24 @@ restart for the next benchmark.
|
|
|
141
161
|
|
|
142
162
|
Python 3.8–3.15, including free-threaded CPython, is supported. The wrapper uses
|
|
143
163
|
standard-library `ctypes` and loads the version-matched bundled native library.
|
|
164
|
+
`run`, `run_all` and `SuiteResult.from_results` require that native library,
|
|
165
|
+
including when inputs are invalid or an aggregate is unavailable. A library
|
|
166
|
+
loading or compatibility error takes precedence over benchmark argument
|
|
167
|
+
validation. Argument checks and their diagnostics are supplied by Rust;
|
|
168
|
+
Python still performs its ordinary numeric type conversions at the boundary.
|
|
169
|
+
Integer subclass ratios are calculated from their `float(...)` conversions;
|
|
170
|
+
Python aggregation retains Python comparisons, including their behavior under
|
|
171
|
+
the caller's FPU mode and subclass overrides. Each requested `result.success`
|
|
172
|
+
value is converted to `bool` once. When aggregating a tuple subclass,
|
|
173
|
+
the factory uses its actual stored elements and length, retaining the original
|
|
174
|
+
tuple in `suite.results`.
|
|
175
|
+
|
|
176
|
+
Benchmark names must be strings. A name subclass may customize an unknown-name
|
|
177
|
+
diagnostic through Python's string operators; its result must also be a string,
|
|
178
|
+
otherwise `TypeError` is raised before any benchmark starts. Compatibility
|
|
179
|
+
covers the documented public API, not incidental dependency names imported by
|
|
180
|
+
internal modules or the exact time temporary Python objects are finalized.
|
|
181
|
+
The CLI does not guarantee context-variable inheritance by its internal threads.
|
|
144
182
|
|
|
145
183
|
```python
|
|
146
184
|
from benchset import run, run_all
|
|
@@ -373,6 +411,8 @@ Swift uses camelCase fields, such as `shortName`, `startedAtUnixSeconds` and
|
|
|
373
411
|
`started_at` datetime; Swift offers `startedAt: Date` for the same instant.
|
|
374
412
|
The frozen Python records use a tuple for results; Swift returns immutable
|
|
375
413
|
value snapshots. Reading the Python globals does not load the native library.
|
|
414
|
+
Their values come from the Rust-generated snapshot bundled with the package;
|
|
415
|
+
builds refresh it from the same sources used to compile the native library.
|
|
376
416
|
|
|
377
417
|
[Calibration values and provenance](native/reference-calibration.json) include
|
|
378
418
|
the original kernel commit, binary SHA-256, raw pooled totals and series
|
|
@@ -402,7 +442,7 @@ pinned release toolchain described under [Publishing](#publishing).
|
|
|
402
442
|
|
|
403
443
|
```toml
|
|
404
444
|
[dependencies]
|
|
405
|
-
benchset = "0.0.
|
|
445
|
+
benchset = "0.0.8"
|
|
406
446
|
# For changes from a local source checkout, use:
|
|
407
447
|
# benchset = { path = "../benchset" }
|
|
408
448
|
```
|
|
@@ -495,6 +535,12 @@ Check `suite.aggregated_scores.has_pi_equivalent` before reading its
|
|
|
495
535
|
`benchset_suite_reason`. Use `benchset_suite_cancel` and `benchset_suite_free`
|
|
496
536
|
for cancellation and cleanup. The same single-use and lifetime rules apply.
|
|
497
537
|
|
|
538
|
+
`benchset_run_all_observed` additionally accepts a result callback for streaming
|
|
539
|
+
each result before the next benchmark starts. Its child handle is borrowed only
|
|
540
|
+
during that callback; copy diagnostics through the single-benchmark getters.
|
|
541
|
+
Returning any nonzero value stops further benchmarks. Python and Swift bindings
|
|
542
|
+
use this entry point; suite ordering and stopping remain in Rust.
|
|
543
|
+
|
|
498
544
|
For example, using the initialized `config` above and no progress callback:
|
|
499
545
|
|
|
500
546
|
```c
|
|
@@ -562,7 +608,7 @@ the same repository. Rust is not required by the consumer.
|
|
|
562
608
|
For a Swift manifest, add:
|
|
563
609
|
|
|
564
610
|
```swift
|
|
565
|
-
.package(url: "https://github.com/mutating/benchset.git", .exact("0.0.
|
|
611
|
+
.package(url: "https://github.com/mutating/benchset.git", .exact("0.0.8"))
|
|
566
612
|
```
|
|
567
613
|
|
|
568
614
|
Add `.product(name: "Benchset", package: "benchset")` to your target's
|
|
@@ -601,7 +647,9 @@ if let fullPi = suite.aggregatedScores.piEquivalent {
|
|
|
601
647
|
```
|
|
602
648
|
|
|
603
649
|
`runAll` keeps the runner reserved across both benchmarks; cancellation also
|
|
604
|
-
applies between
|
|
650
|
+
applies between benchmarks through the native suite's cancellation token.
|
|
651
|
+
Both Swift `runAll` and Python `run_all` call the Rust suite runner through C.
|
|
652
|
+
Native failure/cancellation returns the
|
|
605
653
|
results obtained so far with a `nil` aggregate. Wrapper errors such as allocation
|
|
606
654
|
failure or an unavailable native result throw `BenchsetError`; that call returns
|
|
607
655
|
no `SuiteResult`.
|
|
@@ -677,6 +725,8 @@ controlled initialization failures instead of exhausting machine resources.
|
|
|
677
725
|
Full-suite tests also cover complete ordering, geometric means of unrounded
|
|
678
726
|
ratios, zero/invalid/extreme values, early stopping, serialization and the
|
|
679
727
|
aggregate's presence in each public interface.
|
|
728
|
+
The [core centralization regression matrix](tests/core-centralization-plan.md)
|
|
729
|
+
maps the shared-core contracts to characterization tests and directed mutations.
|
|
680
730
|
|
|
681
731
|
Python coverage includes statements and branches, including CLI subprocesses;
|
|
682
732
|
CI installs a coverage startup hook for those subprocesses. Rust and Swift each
|
|
@@ -42,6 +42,10 @@ private let piReference = try! loadReference(using: .live)
|
|
|
42
42
|
public let piReferenceMachine: ReferenceMachine = piReference.machine
|
|
43
43
|
public let piReferenceRun: ReferenceRun = piReference.run
|
|
44
44
|
|
|
45
|
+
private let nativeDefaults = loadDefaults(using: .live)
|
|
46
|
+
public let defaultWarmupSeconds = nativeDefaults.warmup_seconds
|
|
47
|
+
public let defaultMeasurementSeconds = nativeDefaults.measurement_seconds
|
|
48
|
+
|
|
45
49
|
public struct Progress {
|
|
46
50
|
public let phase: UInt32
|
|
47
51
|
public let workers: UInt32
|
|
@@ -98,15 +102,16 @@ public struct SuiteResult {
|
|
|
98
102
|
|
|
99
103
|
public init(results: [BenchmarkResult]) {
|
|
100
104
|
self.results = results
|
|
101
|
-
let
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
let inputs = results.map {
|
|
106
|
+
BenchsetAggregateInput(benchmark: $0.benchmark.rawValue, status: $0.status,
|
|
107
|
+
pi_equivalent: $0.piEquivalent ?? 0,
|
|
108
|
+
has_pi_equivalent: $0.piEquivalent == nil ? 0 : 1)
|
|
109
|
+
}
|
|
110
|
+
var scores = BenchsetAggregatedScores()
|
|
111
|
+
_ = inputs.withUnsafeBufferPointer { benchset_aggregate($0.baseAddress, UInt64($0.count), &scores) }
|
|
112
|
+
self.aggregatedScores = AggregatedScores(
|
|
113
|
+
piEquivalent: scores.has_pi_equivalent == 0 ? nil : scores.pi_equivalent
|
|
114
|
+
)
|
|
110
115
|
}
|
|
111
116
|
}
|
|
112
117
|
|
|
@@ -164,6 +169,21 @@ internal final class CallbackContext {
|
|
|
164
169
|
// A private function table keeps ownership/error handling testable without
|
|
165
170
|
// changing the public Swift API or replacing the benchmark algorithm.
|
|
166
171
|
internal typealias NativeCallback = @convention(c) (UnsafePointer<BenchsetProgress>?, UnsafeMutableRawPointer?) -> Void
|
|
172
|
+
internal typealias NativeSuiteCallback = @convention(c) (UnsafePointer<BenchsetSuiteProgress>?, UnsafeMutableRawPointer?) -> Void
|
|
173
|
+
internal typealias NativeResultCallback = @convention(c) (UInt32, OpaquePointer?, UnsafeMutableRawPointer?) -> UInt32
|
|
174
|
+
internal struct SuiteAPI {
|
|
175
|
+
var create: () -> OpaquePointer?
|
|
176
|
+
var run: (OpaquePointer, UnsafePointer<BenchsetConfig>, NativeSuiteCallback, NativeResultCallback, UnsafeMutableRawPointer) -> UInt32
|
|
177
|
+
var cancel: (OpaquePointer) -> Void
|
|
178
|
+
var free: (OpaquePointer) -> Void
|
|
179
|
+
|
|
180
|
+
static let live = SuiteAPI(
|
|
181
|
+
create: { benchset_suite_create() },
|
|
182
|
+
run: { benchset_run_all_observed($0, $1, $2, $3, $4) },
|
|
183
|
+
cancel: { benchset_suite_cancel($0) }, free: { benchset_suite_free($0) }
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
|
|
167
187
|
internal struct NativeAPI {
|
|
168
188
|
var abiVersion: () -> UInt32
|
|
169
189
|
var create: () -> OpaquePointer?
|
|
@@ -175,6 +195,7 @@ internal struct NativeAPI {
|
|
|
175
195
|
var reason: (OpaquePointer) -> UnsafePointer<CChar>?
|
|
176
196
|
var version: () -> UnsafePointer<CChar>
|
|
177
197
|
var free: (OpaquePointer) -> Void
|
|
198
|
+
var suite: SuiteAPI = .live
|
|
178
199
|
|
|
179
200
|
static let live = NativeAPI(
|
|
180
201
|
abiVersion: { benchset_abi_version() },
|
|
@@ -186,14 +207,60 @@ internal struct NativeAPI {
|
|
|
186
207
|
)
|
|
187
208
|
}
|
|
188
209
|
|
|
210
|
+
internal func loadDefaults(using native: NativeAPI) -> BenchsetConfig {
|
|
211
|
+
var config = BenchsetConfig()
|
|
212
|
+
guard native.abiVersion() == BENCHSET_ABI_VERSION, native.defaultConfig(&config) == 1 else {
|
|
213
|
+
return BenchsetConfig()
|
|
214
|
+
}
|
|
215
|
+
return config
|
|
216
|
+
}
|
|
217
|
+
|
|
189
218
|
internal func forwardProgress(_ pointer: UnsafePointer<BenchsetProgress>?, _ rawContext: UnsafeMutableRawPointer?) {
|
|
190
219
|
guard let value = pointer?.pointee, let rawContext = rawContext else { return }
|
|
191
220
|
let context = Unmanaged<CallbackContext>.fromOpaque(rawContext).takeUnretainedValue()
|
|
192
|
-
context.callback(
|
|
221
|
+
context.callback(copyProgress(value))
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private func copyProgress(_ value: BenchsetProgress) -> Progress {
|
|
225
|
+
Progress(
|
|
193
226
|
phase: value.phase, workers: value.workers, fraction: value.fraction,
|
|
194
227
|
phaseElapsedSeconds: value.phase_elapsed_seconds,
|
|
195
228
|
phaseDurationSeconds: value.phase_duration_seconds, iterations: value.iterations
|
|
196
|
-
)
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
internal final class SuiteCallbackContext {
|
|
233
|
+
let native: NativeAPI
|
|
234
|
+
let callback: (Benchmark, Progress) -> Void
|
|
235
|
+
var results: [BenchmarkResult] = []
|
|
236
|
+
var error: Error?
|
|
237
|
+
|
|
238
|
+
init(native: NativeAPI, callback: @escaping (Benchmark, Progress) -> Void) {
|
|
239
|
+
self.native = native
|
|
240
|
+
self.callback = callback
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
internal func forwardSuiteProgress(_ pointer: UnsafePointer<BenchsetSuiteProgress>?, _ rawContext: UnsafeMutableRawPointer?) {
|
|
245
|
+
guard let value = pointer?.pointee, let rawContext = rawContext else { return }
|
|
246
|
+
let context = Unmanaged<SuiteCallbackContext>.fromOpaque(rawContext).takeUnretainedValue()
|
|
247
|
+
guard let benchmark = Benchmark(rawValue: value.benchmark) else {
|
|
248
|
+
context.error = BenchsetError.resultUnavailable
|
|
249
|
+
return
|
|
250
|
+
}
|
|
251
|
+
context.callback(benchmark, copyProgress(value.progress))
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
internal func forwardSuiteResult(_ id: UInt32, _ handle: OpaquePointer?, _ rawContext: UnsafeMutableRawPointer?) -> UInt32 {
|
|
255
|
+
guard let rawContext = rawContext else { return 1 }
|
|
256
|
+
let context = Unmanaged<SuiteCallbackContext>.fromOpaque(rawContext).takeUnretainedValue()
|
|
257
|
+
guard let benchmark = Benchmark(rawValue: id), let handle = handle else {
|
|
258
|
+
context.error = BenchsetError.resultUnavailable
|
|
259
|
+
return 1
|
|
260
|
+
}
|
|
261
|
+
do { context.results.append(try readResult(using: context.native, handle: handle, benchmark: benchmark)) }
|
|
262
|
+
catch { context.error = error }
|
|
263
|
+
return context.error == nil ? 0 : 1
|
|
197
264
|
}
|
|
198
265
|
|
|
199
266
|
/// Run from a background queue. Callbacks execute on that queue, not the UI queue.
|
|
@@ -201,9 +268,7 @@ internal func forwardProgress(_ pointer: UnsafePointer<BenchsetProgress>?, _ raw
|
|
|
201
268
|
public final class BenchmarkRunner {
|
|
202
269
|
private let lock = NSLock()
|
|
203
270
|
private let native: NativeAPI
|
|
204
|
-
private var handle: OpaquePointer?
|
|
205
|
-
// nil outside runAll; otherwise keep cancellation across its native handles.
|
|
206
|
-
private var suiteCancelled: Bool?
|
|
271
|
+
private var active: (handle: OpaquePointer, cancel: (OpaquePointer) -> Void, free: (OpaquePointer) -> Void)?
|
|
207
272
|
|
|
208
273
|
public init() { self.native = .live }
|
|
209
274
|
internal init(native: NativeAPI) { self.native = native }
|
|
@@ -211,98 +276,98 @@ public final class BenchmarkRunner {
|
|
|
211
276
|
public func cancel() {
|
|
212
277
|
lock.lock()
|
|
213
278
|
defer { lock.unlock() }
|
|
214
|
-
if
|
|
215
|
-
if let handle = handle { native.cancel(handle) }
|
|
279
|
+
if let active = active { active.cancel(active.handle) }
|
|
216
280
|
}
|
|
217
281
|
|
|
218
|
-
/// Run
|
|
282
|
+
/// Run the native suite. Rust owns its order, early stopping and cancellation.
|
|
219
283
|
public func runAll(
|
|
220
|
-
warmupSeconds: Double =
|
|
221
|
-
measurementSeconds: Double =
|
|
284
|
+
warmupSeconds: Double = defaultWarmupSeconds,
|
|
285
|
+
measurementSeconds: Double = defaultMeasurementSeconds,
|
|
222
286
|
onProgress: @escaping (Benchmark, Progress) -> Void = { _, _ in }
|
|
223
287
|
) throws -> SuiteResult {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
lock.unlock()
|
|
232
|
-
}
|
|
233
|
-
var results: [BenchmarkResult] = []
|
|
234
|
-
for benchmark in [Benchmark.singleCore, .multiCore] {
|
|
235
|
-
let result = try runBenchmark(
|
|
236
|
-
benchmark, warmupSeconds: warmupSeconds, measurementSeconds: measurementSeconds,
|
|
237
|
-
inSuite: true,
|
|
238
|
-
onProgress: { onProgress(benchmark, $0) }
|
|
239
|
-
)
|
|
240
|
-
results.append(result)
|
|
241
|
-
if !result.success { break }
|
|
288
|
+
let current = try acquire(create: native.suite.create, cancel: native.suite.cancel, free: native.suite.free)
|
|
289
|
+
defer { release() }
|
|
290
|
+
var config = try configuration(warmupSeconds: warmupSeconds, measurementSeconds: measurementSeconds)
|
|
291
|
+
let context = SuiteCallbackContext(native: native, callback: onProgress)
|
|
292
|
+
_ = withExtendedLifetime(context) {
|
|
293
|
+
native.suite.run(current, &config, forwardSuiteProgress, forwardSuiteResult,
|
|
294
|
+
Unmanaged.passUnretained(context).toOpaque())
|
|
242
295
|
}
|
|
243
|
-
|
|
296
|
+
if let error = context.error { throw error }
|
|
297
|
+
return SuiteResult(results: context.results)
|
|
244
298
|
}
|
|
245
299
|
|
|
246
300
|
public func run(
|
|
247
301
|
_ benchmark: Benchmark,
|
|
248
|
-
warmupSeconds: Double =
|
|
249
|
-
measurementSeconds: Double =
|
|
302
|
+
warmupSeconds: Double = defaultWarmupSeconds,
|
|
303
|
+
measurementSeconds: Double = defaultMeasurementSeconds,
|
|
250
304
|
onProgress: @escaping (Progress) -> Void = { _ in }
|
|
251
305
|
) throws -> BenchmarkResult {
|
|
252
|
-
try
|
|
253
|
-
|
|
306
|
+
let current = try acquire(create: native.create, cancel: native.cancel, free: native.free)
|
|
307
|
+
defer { release() }
|
|
308
|
+
var config = try configuration(warmupSeconds: warmupSeconds, measurementSeconds: measurementSeconds)
|
|
309
|
+
config.benchmark = benchmark.rawValue
|
|
310
|
+
let context = CallbackContext(onProgress)
|
|
311
|
+
_ = withExtendedLifetime(context) {
|
|
312
|
+
native.run(current, &config, forwardProgress, Unmanaged.passUnretained(context).toOpaque())
|
|
313
|
+
}
|
|
314
|
+
return try readResult(using: native, handle: current, benchmark: benchmark)
|
|
254
315
|
}
|
|
255
316
|
|
|
256
|
-
private func
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
) throws ->
|
|
317
|
+
private func acquire(
|
|
318
|
+
create: () -> OpaquePointer?, cancel: @escaping (OpaquePointer) -> Void,
|
|
319
|
+
free: @escaping (OpaquePointer) -> Void
|
|
320
|
+
) throws -> OpaquePointer {
|
|
260
321
|
lock.lock()
|
|
261
|
-
|
|
262
|
-
guard
|
|
263
|
-
guard
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
322
|
+
defer { lock.unlock() }
|
|
323
|
+
guard active == nil else { throw BenchsetError.alreadyRunning }
|
|
324
|
+
guard native.abiVersion() == BENCHSET_ABI_VERSION else { throw BenchsetError.resultUnavailable }
|
|
325
|
+
guard let current = create() else { throw BenchsetError.allocationFailed }
|
|
326
|
+
active = (current, cancel, free)
|
|
327
|
+
return current
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private func release() {
|
|
331
|
+
lock.lock()
|
|
332
|
+
defer { lock.unlock() }
|
|
333
|
+
let current = active!
|
|
334
|
+
active = nil
|
|
335
|
+
current.free(current.handle)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
private func configuration(warmupSeconds: Double, measurementSeconds: Double) throws -> BenchsetConfig {
|
|
273
339
|
var config = BenchsetConfig()
|
|
274
340
|
guard native.defaultConfig(&config) == 1 else { throw BenchsetError.resultUnavailable }
|
|
275
|
-
config.benchmark = benchmark.rawValue
|
|
276
341
|
config.warmup_seconds = warmupSeconds
|
|
277
342
|
config.measurement_seconds = measurementSeconds
|
|
278
|
-
|
|
279
|
-
_ = withExtendedLifetime(context) {
|
|
280
|
-
native.run(current, &config, forwardProgress, Unmanaged.passUnretained(context).toOpaque())
|
|
281
|
-
}
|
|
282
|
-
var extended = BenchsetResultV2()
|
|
283
|
-
guard native.result(current, &extended, UInt32(MemoryLayout<BenchsetResultV2>.size)) == 1 else {
|
|
284
|
-
throw BenchsetError.resultUnavailable
|
|
285
|
-
}
|
|
286
|
-
let result = extended.base
|
|
287
|
-
var samples: [Sample] = []
|
|
288
|
-
for index in 0..<result.sample_count {
|
|
289
|
-
var sample = BenchsetSample()
|
|
290
|
-
guard native.sample(current, index, &sample) == 1 else { throw BenchsetError.resultUnavailable }
|
|
291
|
-
samples.append(Sample(elapsedSeconds: sample.elapsed_seconds,
|
|
292
|
-
durationSeconds: sample.duration_seconds, iterations: sample.iterations,
|
|
293
|
-
iterationsPerSecond: sample.iterations_per_second))
|
|
294
|
-
}
|
|
295
|
-
let reason = native.reason(current).map { String(cString: $0) }
|
|
296
|
-
return BenchmarkResult(
|
|
297
|
-
benchmark: benchmark, version: String(cString: native.version()), status: result.status,
|
|
298
|
-
reason: reason?.isEmpty == false ? reason : nil,
|
|
299
|
-
score: result.status == BENCHSET_COMPLETED ? result.score : nil, workers: result.workers,
|
|
300
|
-
warmupSeconds: result.warmup_seconds, measurementSeconds: result.measurement_seconds,
|
|
301
|
-
elapsedSeconds: result.elapsed_seconds, iterations: result.iterations, checksum: result.checksum,
|
|
302
|
-
samples: samples, variationPercent: result.has_variation != 0 ? result.variation_percent : nil,
|
|
303
|
-
unstable: result.unstable != 0,
|
|
304
|
-
piEquivalent: result.status == BENCHSET_COMPLETED && extended.has_pi_equivalent != 0
|
|
305
|
-
? extended.pi_equivalent : nil
|
|
306
|
-
)
|
|
343
|
+
return config
|
|
307
344
|
}
|
|
308
345
|
}
|
|
346
|
+
|
|
347
|
+
internal func readResult(using native: NativeAPI, handle: OpaquePointer, benchmark: Benchmark) throws -> BenchmarkResult {
|
|
348
|
+
var extended = BenchsetResultV2()
|
|
349
|
+
guard native.result(handle, &extended, UInt32(MemoryLayout<BenchsetResultV2>.size)) == 1 else {
|
|
350
|
+
throw BenchsetError.resultUnavailable
|
|
351
|
+
}
|
|
352
|
+
let result = extended.base
|
|
353
|
+
var samples: [Sample] = []
|
|
354
|
+
for index in 0..<result.sample_count {
|
|
355
|
+
var sample = BenchsetSample()
|
|
356
|
+
guard native.sample(handle, index, &sample) == 1 else { throw BenchsetError.resultUnavailable }
|
|
357
|
+
samples.append(Sample(elapsedSeconds: sample.elapsed_seconds,
|
|
358
|
+
durationSeconds: sample.duration_seconds, iterations: sample.iterations,
|
|
359
|
+
iterationsPerSecond: sample.iterations_per_second))
|
|
360
|
+
}
|
|
361
|
+
let reason = native.reason(handle).map { String(cString: $0) }
|
|
362
|
+
return BenchmarkResult(
|
|
363
|
+
benchmark: benchmark, version: String(cString: native.version()), status: result.status,
|
|
364
|
+
reason: reason?.isEmpty == false ? reason : nil,
|
|
365
|
+
score: result.status == BENCHSET_COMPLETED ? result.score : nil, workers: result.workers,
|
|
366
|
+
warmupSeconds: result.warmup_seconds, measurementSeconds: result.measurement_seconds,
|
|
367
|
+
elapsedSeconds: result.elapsed_seconds, iterations: result.iterations, checksum: result.checksum,
|
|
368
|
+
samples: samples, variationPercent: result.has_variation != 0 ? result.variation_percent : nil,
|
|
369
|
+
unstable: result.unstable != 0,
|
|
370
|
+
piEquivalent: result.status == BENCHSET_COMPLETED && extended.has_pi_equivalent != 0
|
|
371
|
+
? extended.pi_equivalent : nil
|
|
372
|
+
)
|
|
373
|
+
}
|