Benchmark for Rust and humans

Overview

bma-benchmark

Benchmark for Rust and humans

What is this for

I like testing different libraries, crates and algorithms. I do benchmarks on prototypes almost every day and decided to make a simple dedicated crate for that. Here we go: https://crates.io/crates/bma-benchmark

The benchmark engine is very simple to launch and outputs all required data in a pretty colored readable format.

How to use

Let us create a simple benchmark, using crate macros only:

#[macro_use]
extern crate bma_benchmark;

use std::sync::Mutex;

let n = 100_000_000;
let mutex = Mutex::new(0);
benchmark_start!();
for _ in 0..n {
    let _a = mutex.lock().unwrap();
}
benchmark_print!(n);

The same can also be done with a single "benchmark" macro:

#[macro_use]
extern crate bma_benchmark;

use std::sync::Mutex;

let mutex = Mutex::new(0);
benchmark!(100_000_000, {
    let _a = mutex.lock().unwrap();
    });

Simple benchmark result

Pretty cool, isn't it? Let us create a more complex staged benchmark and compare e.g. Mutex vs RwLock. Staged benchmarks display a comparison table. If the reference stage is specified, the table also contains speed difference for all others.

#[macro_use]
extern crate bma_benchmark;

use std::sync::{Mutex, RwLock};

let n = 10_000_000;
let mutex = Mutex::new(0);
let rwlock = RwLock::new(0);
staged_benchmark_start!("mutex");
for _ in 0..n {
    let _a = mutex.lock().unwrap();
}
staged_benchmark_finish_current!(n);
staged_benchmark_start!("rwlock-read");
for _ in 0..n {
    let _a = rwlock.read().unwrap();
}
staged_benchmark_finish_current!(n);
staged_benchmark_print_for!("rwlock-read");

The same can also be done with a couple of staged_benchmark macros:

#[macro_use]
extern crate bma_benchmark;

use std::sync::{Mutex, RwLock};

let n = 10_000_000;
let mutex = Mutex::new(0);
let rwlock = RwLock::new(0);
staged_benchmark!("mutex", n, {
    let _a = mutex.lock().unwrap();
});
staged_benchmark!("rwlock-read", n, {
    let _a = rwlock.read().unwrap();
});
staged_benchmark_print_for!("rwlock-read");

Or split into functions with benchmark_stage attributes:

use std::sync::{Mutex, RwLock};

#[macro_use]
extern crate bma_benchmark;

#[benchmark_stage(i=10_000_000)]
fn benchmark_mutex(mutex: Mutex<u64>) {
    let _a = mutex.lock().unwrap();
}

#[benchmark_stage(i=10_000_000,name="rwlock-read")]
fn benchmark_rwlock(rwlock: RwLock<u64>) {
    let _a = rwlock.read().unwrap();
}

let mutex = Mutex::new(0);
let rwlock = RwLock::new(0);
benchmark_mutex(mutex);
benchmark_rwlock(rwlock);
staged_benchmark_print_for!("rwlock-read");

Simple benchmark result

Errors

The macros benchmark_print, staged_benchmark_finish and staged_benchmark_finish_current accept error count as an additional parameter.

For code blocks, macros benchmark_check and staged_benchmark_check can be used. In this case, a statement MUST return true for the normal execution and false for errors:

#[macro_use]
extern crate bma_benchmark;

use std::sync::Mutex;

let mutex = Mutex::new(0);
benchmark_check!(10_000_000, {
    mutex.lock().is_ok()
    });

The benchmark_stage attribute has check option, which behaves similarly. If used, the function body MUST (not return but) END with a bool as well.

If any errors are reported, additional columns appear, success count, error count and error rate:

Simple benchmark result

Need anything more complex? Check the crate docs and use structures manually.

Enjoy!

You might also like...
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

Elton is a benchmark utility written in rust aimed to be used to benchmark HTTP calls.

Elton Elton is an HTTP Benchmark utility with options to be used within an HTTP interface. Installation Elton is currently available via Docker or by

😱 Panic messages for humans.

human-panic Panic messages for humans. Handles panics by calling std::panic::set_hook to make errors nice for humans. Documentation Crates.io Why? Whe

The Operating System built for modern humans!
The Operating System built for modern humans!

What is QuantumOS? Quantum OS is a continuation project of my ever loving joy for operating system development. I started with a project called Fluxed

A blazingly fast HTTP client with a magnificent request building syntax, made for humans.
A blazingly fast HTTP client with a magnificent request building syntax, made for humans.

🔗 glue Make requests, select JSON responses, nest them in other requests: A magnificent syntax for blazingly fast cli HTTP calls, made for humans. Ta

ln -s for humans

slink Create symlinks without hassle. Do you know how to use ln -s? Do you really know which comes first the source or the target file? Do you know wh

rusty-riscy is a performance testing and system resource monitoring tool written in Rust to benchmark RISC-V processors.

rusty-riscy rusty-riscy is a performance testing and system resource monitoring tool written in Rust to benchmark RISC-V processors. Objectives To cre

Benchmark over Node.js binding frameworks in Rust

Benchmark over Node.js binding frameworks in Rust

Rust wrapper for COCO benchmark functions.
Rust wrapper for COCO benchmark functions.

Coco Rust bindings for the COCO Numerical Black-Box Optimization Benchmarking Framework. See https://github.com/numbbo/coco and https://numbbo.github.

Verdun is a HTTP stress-test/benchmark tool written in Rust.
Verdun is a HTTP stress-test/benchmark tool written in Rust.

Verdun is a HTTP stress-test/benchmark tool written in Rust. 🦀 It supports testing a single URL, loading multiples URLs from a file or automatically navigating a website (auto discovery)

A http server benchmark tool written in rust 🦀
A http server benchmark tool written in rust 🦀

rsb - rust benchmark rsb is a http server benchmark tool written in rust. The development of this tool is mainly inspired by the bombardier project, a

A rust-based benchmark for BlueField SmartNICs.

Smartbench Smart-bench is a rust-based benchmarking tool for BlueField-series SmartNICs. The purpose is to enable easy testing of BlueField-series Sma

A benchmark of Rust/serde deserializers on configuration files

This program compares the time some serde deserializers take to deserialize some string into a configuration-like struct deriving Deserialize. The ben

A micro-benchmark framework to use with cargo bench
A micro-benchmark framework to use with cargo bench

Glassbench is a micro-benchmark library with memory, to use with cargo bench. Why Run benchmarks and get a comparison with the previous execution carg

Benchmark tool for comparing with other runtimes.

Monoio Benchmark TCP ping-pong(not echo) is a common benchmark for network applications. We will use 1K ping-pong to test performance of different run

It is not about Keanu Reeves but a benchmark tool.
It is not about Keanu Reeves but a benchmark tool.

benchman Features Focus on one-shot benchmark RAII-style Statistics (Average, Median, 95% and 99% percentile) Colored output Tagging Nesting Motivatio

Parses .off (Object File Format) files. This implementation follows this spec from the Princeton Shape Benchmark.

off-rs - A simple .off file parser Parses .off (Object File Format) files. This implementation follows this spec from the Princeton Shape Benchmark. S

hb is an endpoint focused HTTP load testing / benchmark tool.

hb hb is an endpoint focused HTTP load testing / benchmark tool. Description The goal of hb is to provide a simple, robust tool to apply load against

Simple benchmark to compare different Kafka clients performance with similar configuration.

Kafka Producer Benchmark Simple benchmark to compare different clients performance against similar configuration. The project is relatively low tech a

Owner
Altertech
Altertech
A http server benchmark tool written in rust 🦀

rsb - rust benchmark rsb is a http server benchmark tool written in rust. The development of this tool is mainly inspired by the bombardier project, a

Michael 45 Apr 10, 2023
A micro-benchmark framework to use with cargo bench

Glassbench is a micro-benchmark library with memory, to use with cargo bench. Why Run benchmarks and get a comparison with the previous execution carg

Canop 36 Dec 14, 2022
Benchmark tool for comparing with other runtimes.

Monoio Benchmark TCP ping-pong(not echo) is a common benchmark for network applications. We will use 1K ping-pong to test performance of different run

null 6 Oct 10, 2022
It is not about Keanu Reeves but a benchmark tool.

benchman Features Focus on one-shot benchmark RAII-style Statistics (Average, Median, 95% and 99% percentile) Colored output Tagging Nesting Motivatio

Akira Hayakawa 4 Feb 12, 2022
Utility to glitch and dump an AirTag

Airtag dumper Simple utility to glitch and dump the nRF52832 firmware on an airtag using cheap hardware. Requirements: An airtag A bluepill STM32F103

Willem Melching 143 Dec 22, 2022
Statistics-driven benchmarking library for Rust

Criterion.rs Statistics-driven Microbenchmarking in Rust Getting Started | User Guide | Master API Docs | Released API Docs | Changelog | | Criterion.

Brook Heisler 3.1k Jan 8, 2023
A Rust implementation of the PCP instrumentation API

hornet hornet is a Performance Co-Pilot (PCP) Memory Mapped Values (MMV) instrumentation library written in Rust. Contents What is PCP MMV instrumenta

Performance Co-Pilot 33 Sep 15, 2022
A stopwatch library for Rust. Used to time things.

rust-stopwatch This is a simple module used to time things in Rust. Usage To use, add the following line to Cargo.toml under [dependencies]: stopwatch

Chucky Ellison 77 Dec 11, 2022
An intrusive flamegraph profiling tool for rust.

FLAME A cool flamegraph library for rust Flamegraphs are a great way to view profiling information. At a glance, they give you information about how m

null 631 Jan 3, 2023
Experimental one-shot benchmarking/profiling harness for Rust

Iai Experimental One-shot Benchmark Framework in Rust Getting Started | User Guide | Released API Docs | Changelog Iai is an experimental benchmarking

Brook Heisler 409 Dec 25, 2022