Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/base64ct/benches/mod.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / base64ct / benches / mod.rs` 62 lines ยท 1556 bytes Raw Blame History 1 //! `base64ct` benchmarks 2 3 #![feature(test)] 4 extern crate test; 5 6 use base64ct::{Base64Unpadded, Encoding}; 7 use test::Bencher; 8 9 const B64_LEN: usize = 100_000; 10 const RAW_LEN: usize = (3 * B64_LEN) / 4; 11 12 #[inline(never)] 13 fn get_raw_data() -> Vec { 14 (0..RAW_LEN).map(|i| i as u8).collect() 15 } 16 17 #[inline(never)] 18 fn get_b64_data() -> String { 19 (0..B64_LEN) 20 .map(|i| match (i % 64) as u8 { 21 v @ 0..=25 => (v + b'A') as char, 22 v @ 26..=51 => (v - 26 + b'a') as char, 23 v @ 52..=61 => (v - 52 + b'0') as char, 24 62 => '+', 25 _ => '/', 26 }) 27 .collect() 28 } 29 30 #[bench] 31 fn decode_bench(b: &mut Bencher) { 32 let b64_data = get_b64_data(); 33 let mut buf = get_raw_data(); 34 b.iter(|| { 35 let out = Base64Unpadded::decode(test::black_box(&b64_data), &mut buf).unwrap(); 36 test::black_box(out); 37 }); 38 b.bytes = RAW_LEN as u64; 39 } 40 41 #[bench] 42 fn decode_in_place_bench(b: &mut Bencher) { 43 let b64_data = get_b64_data().into_bytes(); 44 let mut buf = b64_data.clone(); 45 b.iter(|| { 46 buf.copy_from_slice(&b64_data[..]); 47 let out = Base64Unpadded::decode_in_place(&mut buf); 48 let _ = test::black_box(out); 49 }); 50 b.bytes = RAW_LEN as u64; 51 } 52 53 #[bench] 54 fn encode_bench(b: &mut Bencher) { 55 let mut buf = get_b64_data().into_bytes(); 56 let raw_data = get_raw_data(); 57 b.iter(|| { 58 let out = Base64Unpadded::encode(test::black_box(&raw_data), &mut buf).unwrap(); 59 test::black_box(out); 60 }); 61 b.bytes = RAW_LEN as u64; 62 }