kolbold/lib.rs
1//! # Kolbold - Performance Measurement Library
2//!
3//! **Kolbold** is a comprehensive Rust library designed to measure the time and memory complexity of code execution,
4//! offering tools for tracking CPU and memory usage in both single-threaded and multi-threaded contexts.
5//! It supports synchronous and asynchronous code execution, making it versatile for various performance analysis needs.
6//!
7//! This library is particularly suited for developers who need to profile and benchmark Rust applications, with detailed metrics available for
8//! time and memory usage across different runtime contexts.
9//!
10//! ## Core Modules
11//!
12//! - [`kolbold_core`](crate::kolbold_core): Contains the core functionality for time and memory measurements, including the `TimeComplexity` and `MemoryComplexity` traits,
13//! and structs for capturing these metrics (`TimeMeasurement`, `MemoryMeasurement`).
14//! - [`kolbold_macros`](crate::kolbold_macros): Provides procedural macros used in simplifying metric implementations.
15//!
16//! ## Primary Features
17//!
18//! - **Time Complexity Measurement**: Track CPU usage and execution time in both synchronous and asynchronous contexts.
19//! - **Memory Complexity Measurement**: Capture memory usage during function execution, with support for synchronous and asynchronous measurement.
20//! - **Thread-Specific Metrics**: Detailed metrics for individual threads in multi-threaded environments, aiding in granular performance analysis.
21//! - **Re-Exports for Convenience**: Common traits and structs, such as `TimeComplexity`, `MemoryComplexity`, `TimeMeasurement`, and `MemoryMeasurement`, are re-exported for ease of use.
22//!
23//! ## Example Usage
24//!
25//! ```rust
26//! use kolbold_core::{TimeComplexity, MemoryComplexity, TimeMeasurement, MemoryMeasurement};
27//! use anyhow::Result;
28//!
29//! // Measure time complexity of a single-threaded synchronous function
30//! fn measure_sync_time() -> Result<()> {
31//! TimeMeasurement::measure_single_thread_sync::<_, _, TimeMeasurement>(|| {
32//! // Example process to measure
33//! let sum: u64 = (0..1_000_000).sum();
34//! println!("Sum: {}", sum);
35//! })
36//! .map(|result| println!("Time measurement successful: {:?}", result))
37//! .unwrap_or_else(|e| eprintln!("Failed to measure time complexity: {}", e));
38//! Ok(())
39//! }
40//!
41//! #[tokio::main]
42//! async fn measure_async_memory() -> Result<()> {
43//! // Measure memory complexity of an async function
44//! MemoryMeasurement::measure_single_thread_async::<_, _, MemoryMeasurement>(|| {
45//! // Async process to measure
46//! let vec: Vec<u64> = (0..1_000_000).collect();
47//! println!("Vector length: {}", vec.len());
48//! })
49//! .await
50//! .map(|result| println!("Memory measurement successful: {:?}", result))
51//! .unwrap_or_else(|e| eprintln!("Failed to measure memory complexity: {}", e));
52//! Ok(())
53//! }
54//! ```
55//!
56//! ## Getting Started
57//!
58//! 1. Add `kolbold` as a dependency in your `Cargo.toml`:
59//!
60//! ```toml
61//! [dependencies]
62//! kolbold = "1.1.0"
63//! ```
64//!
65//! 2. Import the measurement structs (`TimeMeasurement`, `MemoryMeasurement`) for access to time and memory measurement methods.
66//!
67//! 3. If needed, extend functionality by implementing `TimeComplexity` and `MemoryComplexity` traits in your custom types.
68//!
69//! ## More Information
70//!
71//! For details on each component, refer to the documentation for:
72//! - [`kolbold_core`](crate::kolbold_core): Core measurement functionalities
73//! - [`kolbold_macros`](crate::kolbold_macros): Macros that simplify trait implementations
74
75pub use kolbold_core;
76pub use kolbold_macros;