Code Monkey home page Code Monkey logo

cbench's Introduction

[cargo-]cbench

Environment control for benchmarks on Linux/systemd, reducing external noise from benchmark results.

cbench can be used to run any programs. cargo-cbench is a wrapper giving a cargo bench-like interface for running cargo benches conveniently.

Installation

cargo install cbench

Usage

For Rust projects with cargo benches, simply replace cargo bench with cargo cbench:

cargo cbench

This will setup the environment and tweak system configurables (see the next section), run all cargo benchmarks in the current project, and finally revert changes to the original state.

It will only allocate a single exclusive CPU for the benchmark. If your program is multi-threaded, you can allocate more by:

cargo cbench --cpus=1-2

Cargo flags and bench program flags can be passed using the same syntax:

cargo cbench --bench=bench1 --features=feat1 -- --exact foo

For other benchmarking frameworks, run cbench following by the command:

cbench hyperfine /some/benchee

By default, the target command will be run inside a systemd unit named 'cbench.service' as the current user. It will be in a clean environment without inheriting from the current shell. If your command relies on some environment variables, you need to pass them explicitly via --setenv=ENV or --setenv=ENV=VALUE.

More control arguments can be seen in cbench --help.

What it does

These control modules can be enabled or disabled individually via --with= or --without=.

What it does NOT

  • We don't do benchmarks, but we setup environment and tunables for benchmark programs to do benchmarks more reliably. It's expected to be used together with benchmark frameworks/programs like criterion or hyperfine.

  • Environment control does not make programs run faster, but typically in opposite, because we disable frequency boost by default. Our goal is consistency rather than performance.

  • We reduce external noise from tainting the benchmark results. But we cannot magically stabilize it from internal biases. Benchee may still be unstable under different memory (heap and stack) layout caused by environment variables or "being lucky" on program initialization, producing a seemingly random systemic bias through multiple runs. You need to carefully write your benchee program to reduce this effect.

    See stabilizer for more information.

Privileged operations

All settings mentioned above are privileged and machine global. To minimize the impact and security risks, we leverage systemd-run privileged ExecStartPre=/ExecStopPost= commands, thus only the environment setup and reset will be executed with root privileges. Authentication is done by systemd-run itself by default (via PolKit), or you can use --use-sudo to use sudo instead.

Note that no matter whether --use-sudo is used, the program compilation (via cargo build) and benchmark processes are always running as the current user. Never add sudo to cargo cbench itself! Even if you really want to run the target artifact/command as root because, say you are running perf stat --all-kernel, use the option --root for it.

Environment modifications will be reverted after the program exits via systemd ExecStopPost= command, which will do the clean up even if the target process aborted unexpectedly (eg. by Ctrl-C). If they do not, please report a bug.

Credit

cbench's People

Contributors

oxalica avatar

Stargazers

yurzhang avatar  avatar Pauline avatar Alejandro Osornio avatar Yip Coekjan avatar taoky avatar Yanglin Zhang avatar  avatar QuarticCat avatar Rahul Butani avatar

Watchers

 avatar

cbench's Issues

cpufreq/scaling_governor not found

run cargo cbench --cpus=1-8 --bench=mpmc failed

error: failed to read /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor: No such file or directory (os error 2)

I am running on a VM, and CPU info is

CPU(s): 16
On-line CPU(s) list: 0-15
Vendor ID: AuthenticAMD
BIOS Vendor ID: Smdbmds
Model name: AMD EPYC 7K62 48-Core Processor
BIOS Model name: 3.0 CPU @ 2.0GHz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.