-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a41d322
commit abb37fa
Showing
10 changed files
with
527 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use faster_hex::{hex_check_fallback, hex_check_sse}; | ||
|
||
fn bench(c: &mut Criterion) { | ||
let s1 = "Bf9E2d38aceDeeCbbAfccc4B4B7AE"; | ||
let s2 = "ed136fFDdCcC1DbaFE8CB6Df1AdDBAea44aCcC17b0DbC2741F9CeEeaFbE7A51D"; | ||
let s3 = " \u{0} 𐀀G\u{0}𐀀 GG\u{0}𐀀G\u{0}Gࠀ\u{0} 𐀀 \u{0}:\u{0}\u{0}gࠀG G::GG::g𐀀G𐀀\u{0}\u{0}¡𐀀ࠀ\u{0}:GGG Gg𐀀 :\u{0}:gG ¡"; | ||
let s4 = "ed136fFDdCcC1DbaFE8CB6Df1AdDBAea44aCcC17b0DbC2741F9CeEeaFbE7A51D\u{0} 𐀀G\u{0}𐀀 GG\u{0}𐀀G\u{0}Gࠀ\u{0} 𐀀 \u{0}:\u{0}\u{0}gࠀG G::GG::g𐀀G𐀀\u{0}\u{0}¡𐀀ࠀ\u{0}:GGG Gg𐀀 :\u{0}:gG ¡"; | ||
|
||
c.bench_function("bench_check_fallback", move |b| { | ||
b.iter(|| { | ||
let ret1 = hex_check_fallback(s1.as_bytes()); | ||
black_box(ret1); | ||
let ret2 = hex_check_fallback(s2.as_bytes()); | ||
black_box(ret2); | ||
let ret3 = hex_check_fallback(s3.as_bytes()); | ||
black_box(ret3); | ||
let ret4 = hex_check_fallback(s4.as_bytes()); | ||
black_box(ret4); | ||
}) | ||
}); | ||
|
||
c.bench_function("bench_check_sse", move |b| { | ||
b.iter(|| { | ||
let ret1 = unsafe { hex_check_sse(s1.as_bytes()) }; | ||
black_box(ret1); | ||
let ret2 = unsafe { hex_check_sse(s2.as_bytes()) }; | ||
black_box(ret2); | ||
let ret3 = unsafe { hex_check_sse(s3.as_bytes()) }; | ||
black_box(ret3); | ||
let ret4 = unsafe { hex_check_sse(s4.as_bytes()) }; | ||
black_box(ret4); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, bench); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use faster_hex::{hex_decode, hex_decode_fallback, hex_decode_unchecked, hex_string, hex_encode_fallback}; | ||
use rustc_hex::{FromHex, ToHex}; | ||
|
||
fn bench(c: &mut Criterion) { | ||
let s = "Day before yesterday I saw a rabbit, and yesterday a deer, and today, you."; | ||
|
||
c.bench_function("bench_rustc_hex", move |b| { | ||
b.iter(|| { | ||
let ret = s.as_bytes().to_hex(); | ||
black_box(ret); | ||
}) | ||
}); | ||
|
||
c.bench_function("bench_hex_hex", move |b| { | ||
b.iter(|| { | ||
let ret = hex::encode(s); | ||
black_box(ret); | ||
}) | ||
}); | ||
|
||
c.bench_function("bench_faster_hex", move |b| { | ||
b.iter(|| { | ||
let ret = hex_string(s.as_bytes()).unwrap(); | ||
black_box(ret); | ||
}) | ||
}); | ||
|
||
c.bench_function("bench_faster_hex_fallback", move |b| { | ||
b.iter(|| { | ||
let bytes = s.as_bytes(); | ||
let mut buffer = vec![0; bytes.len() * 2]; | ||
let ret = hex_encode_fallback(bytes, &mut buffer); | ||
black_box(ret); | ||
}) | ||
}); | ||
|
||
c.bench_function("bench_rustc_hex_decode", move |b| { | ||
let hex = s.as_bytes().to_hex(); | ||
b.iter(|| { | ||
let ret: Vec<u8> = hex.from_hex().unwrap(); | ||
black_box(ret); | ||
}) | ||
}); | ||
|
||
c.bench_function("bench_faster_hex_decode", move |b| { | ||
let hex = hex_string(s.as_bytes()).unwrap(); | ||
let len = s.as_bytes().len(); | ||
b.iter(|| { | ||
let mut dst = Vec::with_capacity(len); | ||
dst.resize(len, 0); | ||
let ret = hex_decode(hex.as_bytes(), &mut dst); | ||
black_box(ret); | ||
}) | ||
}); | ||
|
||
c.bench_function("bench_faster_hex_decode_unchecked", move |b| { | ||
let hex = hex_string(s.as_bytes()).unwrap(); | ||
let len = s.as_bytes().len(); | ||
b.iter(|| { | ||
let mut dst = Vec::with_capacity(len); | ||
dst.resize(len, 0); | ||
let ret = hex_decode_unchecked(hex.as_bytes(), &mut dst); | ||
black_box(ret); | ||
}) | ||
}); | ||
|
||
c.bench_function("bench_faster_hex_decode_fallback", move |b| { | ||
let hex = hex_string(s.as_bytes()).unwrap(); | ||
let len = s.as_bytes().len(); | ||
b.iter(|| { | ||
let mut dst = Vec::with_capacity(len); | ||
dst.resize(len, 0); | ||
let ret = hex_decode_fallback(hex.as_bytes(), &mut dst); | ||
black_box(ret); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, bench); | ||
criterion_main!(benches); |
This file was deleted.
Oops, something went wrong.
Empty file.
Oops, something went wrong.