{"id":29210685,"url":"https://github.com/embarkstudios/tiny-bench","last_synced_at":"2026-03-04T18:04:07.729Z","repository":{"id":40601161,"uuid":"494366799","full_name":"EmbarkStudios/tiny-bench","owner":"EmbarkStudios","description":"A tiny benchmarking library","archived":false,"fork":false,"pushed_at":"2024-09-10T08:39:01.000Z","size":67,"stargazers_count":59,"open_issues_count":0,"forks_count":2,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-09-11T10:31:22.162Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EmbarkStudios.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-APACHE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-05-20T07:35:03.000Z","updated_at":"2024-09-10T08:38:12.000Z","dependencies_parsed_at":"2024-01-13T10:40:51.477Z","dependency_job_id":"e0482bb6-1b3c-4766-9c0e-0f6c74e93727","html_url":"https://github.com/EmbarkStudios/tiny-bench","commit_stats":{"total_commits":38,"total_committers":5,"mean_commits":7.6,"dds":"0.21052631578947367","last_synced_commit":"d40e0c062e493756e2ef74d7b0e3c314ac67d5c2"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/EmbarkStudios/tiny-bench","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmbarkStudios%2Ftiny-bench","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmbarkStudios%2Ftiny-bench/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmbarkStudios%2Ftiny-bench/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmbarkStudios%2Ftiny-bench/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EmbarkStudios","download_url":"https://codeload.github.com/EmbarkStudios/tiny-bench/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmbarkStudios%2Ftiny-bench/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263215297,"owners_count":23431895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-02T21:07:34.693Z","updated_at":"2026-03-04T18:04:07.680Z","avatar_url":"https://github.com/EmbarkStudios.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- Allow this file to not have a first line heading --\u003e\n\u003c!-- markdownlint-disable-file MD041 no-emphasis-as-heading --\u003e\n\n\u003c!-- inline html --\u003e\n\u003c!-- markdownlint-disable-file MD033 --\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n# `🛠 tiny-bench`\n\n**A tiny benchmarking library**\n\n[![Embark](https://img.shields.io/badge/embark-open%20source-blueviolet.svg)](https://embark.dev)\n[![Embark](https://img.shields.io/badge/discord-ark-%237289da.svg?logo=discord)](https://discord.gg/dAuKfZS)\n[![Crates.io](https://img.shields.io/crates/v/tiny-bench.svg)](https://crates.io/crates/tiny-bench)\n[![Docs](https://docs.rs/tiny-bench/badge.svg)](https://docs.rs/tiny-bench)\n[![dependency status](https://deps.rs/repo/github/EmbarkStudios/tiny-bench/status.svg)](https://deps.rs/repo/github/EmbarkStudios/tiny-bench)\n[![Build status](https://github.com/EmbarkStudios/tiny-bench/workflows/CI/badge.svg)](https://github.com/EmbarkStudios/tiny-bench/actions)\n\u003c/div\u003e\n\n## The library\n\nA benchmarking and timing library inspired by [Criterion](https://github.com/bheisler/criterion.rs).  \nInspired in this case means copying the things that criterion does well (and I do mean ctrl-c), like\nstatistical analysis of results, trimming that down, and leaving much of the customizability out.  \n[Criterion](https://github.com/bheisler/criterion.rs) is MIT licensed, please see the license at that repo or\n[here](tiny-bench/src/benching/criterion/CRITERION-LICENSE-MIT).\n\n## Primary goals\n\n* Reliable results\n* Fast build\n* No dependencies\n* Simple code that anyone can read, understand, and modify\n\n## Purpose\n\nSometimes you just need some back-of-the-envelope calculations of how long something takes.\nThis library aims to fulfill that need and not much else.\n\nThe aim of the benchmarking is to be accurate enough to deliver reliable benchmarks with a minimal footprint,\nso that you can easily get a sense of whether you're going down a bad path.\n\nThe aim of the timing is to provide something that will let you figure out the same with\nthe caveat of not being as reliable. It times some code so that you can get a sense of\nhow much time pieces of your code takes to run.\n\n## Caveats\n\nThis library does not aim to provide production grade analysis tooling. It just prints data to stdout to guide you.\nIf you need advanced analysis [Criterion](https://github.com/bheisler/criterion.rs) has tooling better suited to that.  \nIf you need to find where your application spends its time [flamegraph](https://github.com/flamegraph-rs/flamegraph)\nmay be better suited for that.  \nIf you need to track single pieces of your application when it's running [Tracing](https://github.com/tokio-rs/tracing)\nmay be better suited for that.  \nLastly, if you want an even smaller benchmarking library, check\nout [benchmark-simple](https://github.com/jedisct1/rust-benchmark-simple).\n\n## Unimplemented\n\nThere are a few statistical measures that would be nice to have but are limited by the methods used by this library.  \nSince it potentially runs billions of iterations, calculating statistics based on seeing all iterations such as median,\nstandard deviation, and percentiles are not feasible without caching data to disk.\nTherefore, measures like variance, or median are prefixed by \"sample\" as they are not related to individual iteration times, \nbut a comparison between samples.\n\nThere is no arg-parsing or bench-matching in this library, so you can't run cargo bench \u003ctest-matcher\u003e.\nInstead, the user needs to put different benches into functions, and add/remove those functions from bench main.\nThe reason for this is that those libraries are heavy-weight and would likely require some macros to\nselect which benches to run which decreases readability and understandability.\n\n## Examples\n\n### Getting a hint of what parts of your application take time\n\n\"I have this iterator, and I'd like to get some sense of how long it takes to complete\"\n\n```Rust\nuse std::time::Duration;\nuse tiny_bench::Timeable;\n\npub fn main() {\n    let v = (0..100)\n        .map(|a| {\n            my_expensive_call();\n            a\n        })\n        .timed()\n        .max();\n    assert_eq!(99, v.unwrap())\n    // prints:\n    // anonymous [100.0 iterations in 512.25ms]:\n    // elapsed\t[min mean max]:\t[5.06ms 5.12ms 5.20ms]\n}\n\nfn my_expensive_call() {\n    std::thread::sleep(Duration::from_millis(5));\n}\n```\n\n\"I have this loop that has side effects, and I'd like to time its execution\"\n\n```Rust\nuse tiny_bench::run_timed_from_iterator;\n\nfn main() {\n    let generator = 0..100;\n    let mut spooky_calculation = 0;\n    let results = run_timed_from_iterator(generator, |i| {\n        spooky_calculation += i;\n    });\n    results.pretty_print();\n    assert_eq!(4950, spooky_calculation);\n}\n```\n\n### More involved comparisons\n\n\"My algorithm is pretty stupid, but I'm only sorting vectors with a max-length of 5, so maybe it doesn't matter\nin the grand scheme of things\"\n\n```Rust\nuse tiny_bench::BenchmarkConfig;\n\nfn main() {\n    let v = vec![10, 5, 3, 8, 7, 5];\n    tiny_bench::run_bench(\u0026BenchmarkConfig::default(), || {\n        let sorted = bad_sort(v.clone());\n        assert_eq!(vec![3, 5, 5, 7, 8, 10], sorted);\n    })\n    // Prints:\n    // anonymous [2.5M iterations in 4.99s with 100.0 samples]:\n    // elapsed\t[min mean max]:\t[2.14µs 2.01µs 2.14µs]\n}\n\nfn bad_sort(mut v: Vec\u003cu32\u003e) -\u003e Vec\u003cu32\u003e {\n    let mut sorted = Vec::with_capacity(v.len());\n    while !v.is_empty() {\n        let mut min_val = u32::MAX;\n        let mut min_index = 0;\n        for i in 0..v.len() {\n            if v[i] \u003c min_val {\n                min_index = i;\n                min_val = v[i];\n            }\n        }\n        sorted.push(min_val);\n        v.remove(min_index);\n    }\n    sorted\n}\n```\n\n\"I'd like to compare different implementations with each other\"\n\n```Rust\nuse tiny_bench::black_box;\n\nfn main() {\n    // Results are compared by label\n    let label = \"compare_functions\";\n    tiny_bench::bench_labeled(label, my_slow_function);\n    tiny_bench::bench_labeled(label, my_faster_function);\n    // prints:\n    //compare_functions [30.3 thousand iterations in 5.24s with 100.0 samples]:\n    //elapsed\t[min mean max]:\t[246.33µs 175.51µs 246.33µs]\n    //compare_functions [60.6 thousand iterations in 5.24s with 100.0 samples]:\n    //elapsed\t[min mean max]:\t[87.67µs 86.42µs 87.67µs]\n    //change\t[min mean max]:\t[-49.6111% -50.7620% -64.4102%] (p = 0.00)\n}\n\nfn my_slow_function() {\n    let mut num_iters = 0;\n    for _ in 0..10_000 {\n        num_iters += black_box(1);\n    }\n    assert_eq!(10_000, black_box(num_iters))\n}\n\nfn my_faster_function() {\n    let mut num_iters = 0;\n    for _ in 0..5_000 {\n        num_iters += black_box(1);\n    }\n    assert_eq!(5_000, black_box(num_iters))\n}\n\n```\n\n## Contribution\n\n[![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v1.4-ff69b4.svg)](CODE_OF_CONDUCT.md)\n\nWe welcome community contributions to this project.\n\nPlease read our [Contributor Guide](CONTRIBUTING.md) for more information on how to get started.\nPlease also read our [Contributor Terms](CONTRIBUTING.md#contributor-terms) before you make any contributions.\n\nAny contribution intentionally submitted for inclusion in an Embark Studios project, shall comply with the Rust standard\nlicensing model (MIT OR Apache 2.0) and therefore be dual licensed as described below, without any additional terms or\nconditions:\n\n### License\n\nThis contribution is dual licensed under EITHER OF\n\n* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e)\n* MIT license ([LICENSE-MIT](LICENSE-MIT) or \u003chttp://opensource.org/licenses/MIT\u003e)\n\nat your option.\n\nFor clarity, \"your\" refers to Embark or any other licensee/user of the contribution.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fembarkstudios%2Ftiny-bench","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fembarkstudios%2Ftiny-bench","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fembarkstudios%2Ftiny-bench/lists"}