Skip to content

Commit

Permalink
Merge branch 'master' into nagisa/version-bumps
Browse files Browse the repository at this point in the history
  • Loading branch information
lemmih committed Aug 11, 2023
2 parents aaeeb37 + c0461a6 commit 8fa9d6d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ default = ["rayon", "plotters", "cargo_bench_support"]
real_blackbox = []

# Enable async/await support
async = ["futures"]
async = []

# These features enable built-in support for running async benchmarks on each different async
# runtime.
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div align="center">Statistics-driven Microbenchmarking in Rust</div>

<div align="center">
<a href="https://bheisler.github.io/criterion.rs/book/getting_started.html">Getting Started</a>
<a href="https://bheisler.github.io/criterion.rs/book/getting_started.html">Getting Started</a>
|
<a href="https://bheisler.github.io/criterion.rs/book/index.html">User Guide</a>
|
Expand All @@ -15,14 +15,10 @@
</div>

<div align="center">
<a href="https://github.com/bheisler/criterion.rs/actions/workflows/ci.yaml">
<a href="https://github.com/bheisler/criterion.rs/actions/workflows/ci.yaml">
<img src="https://img.shields.io/github/checks-status/rgeometry/rgeometry/main?label=tests&logo=github" alt="GitHub branch checks state">
</a>
|
<a href="https://ci.appveyor.com/project/bheisler/criterion-rs-vt9fl">
<img src="https://ci.appveyor.com/api/projects/status/4255ads9ctpupcl2?svg=true" alt="Appveyor">
</a>
|
<a href="https://crates.io/crates/criterion">
<img src="https://img.shields.io/crates/v/criterion.svg" alt="Crates.io">
</a>
Expand All @@ -31,6 +27,7 @@
Criterion.<span></span>rs helps you write fast code by detecting and measuring performance improvements or regressions, even small ones, quickly and accurately. You can optimize with confidence, knowing how each change affects the performance of your code.

## Table of Contents

- [Table of Contents](#table-of-contents)
- [Features](#features)
- [Quickstart](#quickstart)
Expand Down
34 changes: 0 additions & 34 deletions appveyor.yml

This file was deleted.

5 changes: 5 additions & 0 deletions book/src/user_guide/html_report.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# HTML Report

Starting with Criterion.rs 0.4.0 HTML reports must be explicitly enabled via the `html_reports` [feature](https://doc.rust-lang.org/cargo/reference/features.html#dependency-features):
```toml
[dev-dependencies]
criterion = {version = "0.4.0", features = ["html_reports"] }
```
Criterion.rs can generate an HTML report displaying the results of the benchmark under
`target/criterion/reports/index.html`. By default, the plots are generated using
[gnuplot](http://www.gnuplot.info/) if it is available, or the
Expand Down
35 changes: 34 additions & 1 deletion src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,35 @@ pub fn iter_count(iterations: u64) -> String {
}
}

/// Format a number with thousands separators.
// Based on the corresponding libtest functionality, see
// https://github.com/rust-lang/rust/blob/557359f92512ca88b62a602ebda291f17a953002/library/test/src/bench.rs#L87-L109
fn thousands_sep(mut n: u64, sep: char) -> String {
use std::fmt::Write;
let mut output = String::new();
let mut trailing = false;
for &pow in &[9, 6, 3, 0] {
let base = 10_u64.pow(pow);
if pow == 0 || trailing || n / base != 0 {
if !trailing {
write!(output, "{}", n / base).unwrap();
} else {
write!(output, "{:03}", n / base).unwrap();
}
if pow != 0 {
output.push(sep);
}
trailing = true;
}
n %= base;
}

output
}

/// Format a value as an integer, including thousands-separators.
pub fn integer(n: f64) -> String {
format!("{}", n as u64)
thousands_sep(n as u64, ',')
}

#[cfg(test)]
Expand Down Expand Up @@ -101,4 +128,10 @@ mod test {
float *= 2.0;
}
}

#[test]
fn integer_thousands_sep() {
let n = 140352319.0;
assert_eq!(integer(n), "140,352,319");
}
}

0 comments on commit 8fa9d6d

Please sign in to comment.