add concat-string macro
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -99,6 +99,12 @@ version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
|
||||
|
||||
[[package]]
|
||||
name = "concat-string"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7439becb5fafc780b6f4de382b1a7a3e70234afe783854a4702ee8adbb838609"
|
||||
|
||||
[[package]]
|
||||
name = "criterion"
|
||||
version = "0.5.1"
|
||||
@ -361,6 +367,7 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||
name = "rust_benchmark"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"concat-string",
|
||||
"criterion",
|
||||
]
|
||||
|
||||
|
@ -10,6 +10,7 @@ path = "src/lib.rs"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
concat-string = "1.0.1"
|
||||
criterion = "0.5.1"
|
||||
|
||||
[[bench]]
|
||||
|
@ -1,6 +1,6 @@
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
use rust_benchmark::{concat_with_format, concat_with_plus};
|
||||
use rust_benchmark::{concat_with_concat_string_macro_crate, concat_with_format, concat_with_plus};
|
||||
|
||||
const A: &str = "post";
|
||||
const B: &str = "/fasjhiofasihofas";
|
||||
@ -12,6 +12,9 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("concat with plus", |b| {
|
||||
b.iter(|| concat_with_plus(black_box(A), black_box(B)));
|
||||
});
|
||||
c.bench_function("concat with concat-string crate", |b| {
|
||||
b.iter(|| concat_with_concat_string_macro_crate(black_box(A), black_box(B)));
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
|
@ -1,3 +1,6 @@
|
||||
#[macro_use(concat_string)]
|
||||
extern crate concat_string;
|
||||
|
||||
pub fn concat_with_format(a: &str, b: &str) -> String {
|
||||
let c = format!("{} {}", a, b);
|
||||
c
|
||||
@ -8,6 +11,11 @@ pub fn concat_with_plus(a: &str, b: &str) -> String {
|
||||
c
|
||||
}
|
||||
|
||||
pub fn concat_with_concat_string_macro_crate(a: &str, b: &str) -> String {
|
||||
let c = concat_string!(a, " ", b);
|
||||
c
|
||||
}
|
||||
|
||||
pub fn add(left: usize, right: usize) -> usize {
|
||||
left + right
|
||||
}
|
||||
|
Reference in New Issue
Block a user