libspot
A safe Rust wrapper(using FFI) for the libspot time series anomaly detection library.
Installation
Quick Start
use ;
Examples
See the examples directory for more usage examples.
You can run the examples with cargo run --example <example_name>:
Correctness & Performance
This wrapper provides identical results to the original C implementation. The basic.rs example processes 50M samples and produces the exact same anomaly counts and thresholds as the reference basic.c implementation:
| Metric | C Implementation | Rust Wrapper | Identical |
|---|---|---|---|
| Anomalies | 90,007 | 90,007 | ✓ |
| Excess | 7,829 | 7,829 | ✓ |
| Normal | 49,902,164 | 49,902,164 | ✓ |
| Z | 6.237668 | 6.237668 | ✓ |
| T | 6.236165 | 6.236165 | ✓ |
| Performance | ~1.276820s | ~1.372725s | ✓ |
We run the benchmark with:
- Rust:
cargo run -r --example basic(with-rflag to run the example in release mode). - C:
cc -O3 -o /tmp/basic examples/basic.c -Idist/ -Ldist/ -l:libspot.so.2.0b5 -lm && LD_LIBRARY_PATH=dist /tmp/basic(with-O3flag to compile the example in release mode).
As you can see, the performance is very close. You may get different results due to the different hardware and environment, but the results should be very similar.
License
This project is licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0) to comply with the underlying libspot C library license.
Alternative
For a pure Rust implementation without FFI dependencies, see the libspot-rs crate.