no constant folding
This commit is contained in:
parent
a3b403d155
commit
185e517e96
@ -2,12 +2,15 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
use rust_benchmark::{concat_with_format, concat_with_plus};
|
||||
|
||||
const A: &str = "post";
|
||||
const B: &str = "/fasjhiofasihofas";
|
||||
|
||||
pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("concat with format", |b| {
|
||||
b.iter(|| concat_with_format());
|
||||
});
|
||||
c.bench_function("concat with plus", |b| {
|
||||
b.iter(|| concat_with_plus());
|
||||
b.iter(|| concat_with_plus(black_box(A), black_box(B)));
|
||||
});
|
||||
c.bench_function("concat with format", |b| {
|
||||
b.iter(|| concat_with_format(black_box(A), black_box(B)));
|
||||
});
|
||||
}
|
||||
|
||||
|
21
src/lib.rs
21
src/lib.rs
@ -1,20 +1,17 @@
|
||||
const A: &str = "post";
|
||||
const B: &str = "/fasjhiofasihofas";
|
||||
pub fn concat_with_format(a: &str, b: &str) -> String {
|
||||
let c = format!("{} {}", a, b);
|
||||
c
|
||||
}
|
||||
|
||||
pub fn concat_with_plus(a: &str, b: &str) -> String {
|
||||
let c = a.to_string() + " " + b;
|
||||
c
|
||||
}
|
||||
|
||||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
}
|
||||
|
||||
pub fn concat_with_plus() -> String {
|
||||
let c = A.to_string() + " " + B;
|
||||
c
|
||||
}
|
||||
|
||||
pub fn concat_with_format() -> String {
|
||||
let c = format!("{} {}", A, B);
|
||||
c
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
Loading…
x
Reference in New Issue
Block a user