#memory #metrics #time #metrics-collection #measurement #measure #kolbold

macro kolbold_macros

A Rust library for memory and time metrics collection

1 unstable release

new 0.1.0 Nov 7, 2024

#474 in Procedural macros

Download history 78/week @ 2024-11-02

78 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.0.1"

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(|| {
        // 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(|| {
        // 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(|| {
        // 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 MIT License. See the Apache 2.0 License file for details.

Contact

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

Dependencies

~230–670KB
~16K SLoC