1 unstable release

0.1.0 Nov 7, 2024

#1251 in Procedural macros

48 downloads per month
Used in 2 crates

Apache-2.0

3KB

Kolbold

Kolbold is a Rust library designed to measure time and memory complexity for code execution. It provides tools for gathering system metrics such as CPU and memory usage, making it ideal for performance analysis in both single-threaded and multi-threaded environments.

Features

  • Time Complexity Measurement: Collects CPU usage and execution time in synchronous and asynchronous contexts.
  • Memory Complexity Measurement: Measures memory usage during code execution.
  • Thread-Specific Metrics: Captures detailed metrics for individual threads in multi-threaded scenarios.
  • Easy Integration: Simple API for adding performance measurement to your Rust code.

Table of Contents

Installation

To use kolbold, add the following line to your Cargo.toml:

[dependencies]
kolbold = "1.2.2"

Then, include it in your code:

use kolbold::time::time_measurement::TimeComplexity;
use kolbold::memory::memory_measurement::MemoryComplexity;

Usage

Time Complexity

Measure time complexity for a synchronous, single-threaded function:

use kolbold::time::time_measurement::{TimeComplexity, TimeMeasurement};
use anyhow::Result;

fn main() -> Result<()> {
    let result = TimeMeasurement::measure_single_thread_sync::<_, _, TimeMeasurement>(|| {
        // Your code to be measured
        let sum: u64 = (0..1_000_000).sum();
        println!("Sum: {}", sum);
    })?;

    println!("Measurement Data: {:?}", result);
    Ok(())
}

Measure time complexity for an asynchronous, single-threaded function:

use kolbold::time::time_measurement::{TimeComplexity, TimeMeasurement};
use anyhow::Result;
use tokio::main;

#[main]
async fn async_main() -> Result<()> {
    let result = TimeMeasurement::measure_single_thread_async::<_, _, TimeMeasurement>(|| {
        // Your async code to be measured
        let product: u64 = (1..100).product();
        println!("Product: {}", product);
    }).await?;

    println!("Measurement Data: {:?}", result);
    Ok(())
}

Memory Complexity

Measure memory usage for a synchronous function:

use kolbold::memory::memory_measurement::{MemoryComplexity, MemoryMeasurement};
use anyhow::Result;

fn main() -> Result<()> {
    let result = MemoryMeasurement::measure_single_thread_sync::<_, _, MemoryMeasurement>(|| {
        // Code to measure memory usage
        let vec: Vec<u64> = (0..1_000_000).collect();
        println!("Vector length: {}", vec.len());
    })?;

    println!("Memory Measurement Data: {:?}", result);
    Ok(())
}

Documentation

For detailed API documentation and examples, refer to the full documentation.

Contributing

Contributions are welcome! If you want to contribute to the project, please check out the Contributing guidelines for more information.

License

This project is licensed under the Apache 2.0 License License. See the Apache 2.0 License file for details.

Contact

For any inquiries or further information, feel free to reach out:

Dependencies

~220–660KB
~16K SLoC