oxedyne/fe2o3/fe2o3_jdat/benches/bytes.rs
10.1 KiB, 5 runs
created by r1870400018:431, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | // To switch to nightly to run these benchmarks: |
| 2 | // > rustup override set nightly |
| 3 | // > clear;clear;cargo bench |
| 4 | // To switch back to stable: |
| 5 | // > rustup override set stable |
| 6 | // |
| 7 | // Run this with |
| 8 | // > cargo bench |
| 9 | #![feature(test)] |
| 10 | extern crate test; |
| 11 | |
| 12 | use oxedyne_fe2o3_core::prelude::*; |
| 13 | use oxedyne_fe2o3_jdat::{ |
| 14 | prelude::*, |
| 15 | daticle::Dat, |
| 16 | }; |
| 17 | |
| 18 | use test::Bencher; |
| 19 | |
| 20 | //const SMALL_LEN: usize = 10; |
| 21 | //const LARGE_LEN: usize = 1000; |
| 22 | //const FILL_U8: u8 = 42; |
| 23 | //const FILL_U64: u64 = 42; |
| 24 | // |
| 25 | //fn u8_to_bytes(v: u8, buf: &mut Vec<u8>) { |
| 26 | // buf.push(Dat::U8_CODE); |
| 27 | // buf.extend_from_slice(&v.to_be_bytes()); |
| 28 | //} |
| 29 | // |
| 30 | //fn u8_to_bytes2(v: u8, mut buf: Vec<u8>) -> Vec<u8> { |
| 31 | // buf.push(Dat::U8_CODE); |
| 32 | // buf.push(v.to_be_bytes()[0]); |
| 33 | // buf |
| 34 | //} |
| 35 | // |
| 36 | //fn u64_to_bytes(v: u64, buf: &mut Vec<u8>) { |
| 37 | // buf.push(Dat::U64_CODE); |
| 38 | // buf.extend_from_slice(&v.to_be_bytes()); |
| 39 | //} |
| 40 | // |
| 41 | //fn u64_to_bytes2(v: u64, mut buf: Vec<u8>) -> Vec<u8> { |
| 42 | // buf.push(Dat::U64_CODE); |
| 43 | // buf.append(&mut v.to_be_bytes().to_vec()); |
| 44 | // buf |
| 45 | //} |
| 46 | // |
| 47 | //fn u64_to_bytes3(v: u64, buf: &mut Vec<u8>) { |
| 48 | // buf.push(Dat::U64_CODE); |
| 49 | // for b in v.to_be_bytes() { |
| 50 | // buf.push(b); |
| 51 | // } |
| 52 | //} |
| 53 | // |
| 54 | //fn u64_to_bytes4(v: u64, mut buf: Vec<u8>) -> Vec<u8> { |
| 55 | // let mut pre = vec![0u8;9]; |
| 56 | // pre[0] = Dat::U64_CODE; |
| 57 | // let vbyts = v.to_be_bytes(); |
| 58 | // for i in 0..vbyts.len() { |
| 59 | // pre[1 + i] = vbyts[i]; |
| 60 | // } |
| 61 | // buf.append(&mut pre); |
| 62 | // buf |
| 63 | //} |
| 64 | // |
| 65 | //fn c64_to_bytes(v: u64, buf: &mut Vec<u8>) { |
| 66 | // let byts: [u8; 8] = v.to_be_bytes(); |
| 67 | // let mut count: usize = 8; |
| 68 | // for byt in &byts[..] { |
| 69 | // if *byt == 0 { |
| 70 | // count -= 1; |
| 71 | // } else { |
| 72 | // break; |
| 73 | // } |
| 74 | // } |
| 75 | // buf.push(Dat::C64_CODE_START + count as u8); |
| 76 | // while count > 0 { |
| 77 | // buf.push(byts[8-count]); |
| 78 | // count -= 1; |
| 79 | // } |
| 80 | //} |
| 81 | // |
| 82 | //fn daticle_bytes(b: &Vec<u8>, mut buf: &mut Vec<u8>) { |
| 83 | // buf.push(Dat::BC64_CODE); |
| 84 | // buf = Dat::C64(b.len() as u64).to_bytes(buf); |
| 85 | // buf.extend_from_slice(b); |
| 86 | //} |
| 87 | // |
| 88 | //fn daticle_bytes2(mut b: Vec<u8>, mut buf: Vec<u8>) -> Vec<u8> { |
| 89 | // buf.push(Dat::BU64_CODE); |
| 90 | // //Dat::C64(b.len() as u64).to_bytes(&mut buf); |
| 91 | // buf.extend_from_slice(&(b.len() as u64).to_be_bytes()); |
| 92 | // buf.append(&mut b); |
| 93 | // buf |
| 94 | //} |
| 95 | // |
| 96 | //fn daticle_bytes3(b: &Vec<u8>, buf: &mut Vec<u8>) { |
| 97 | // buf.push(Dat::BU64_CODE); |
| 98 | // buf.extend_from_slice(&(b.len() as u64).to_be_bytes()); |
| 99 | // buf.extend_from_slice(b); |
| 100 | //} |
| 101 | // |
| 102 | //fn wrap_bytes(byts: &mut Vec<u8>) { |
| 103 | // let mut pre = Vec::new(); |
| 104 | // pre.push(Dat::BC64_CODE); |
| 105 | // Dat::C64(byts.len() as u64).to_bytes(&mut pre); |
| 106 | // byts.splice(0..0, pre.drain(..)); |
| 107 | //} |
| 108 | // |
| 109 | //fn wrap_bytes2(mut byts: Vec<u8>) -> Vec<u8> { |
| 110 | // let mut pre = Vec::new(); |
| 111 | // pre.push(Dat::BC64_CODE); |
| 112 | // Dat::C64(byts.len() as u64).to_bytes(&mut pre); |
| 113 | // pre.append(&mut byts); |
| 114 | // pre |
| 115 | //} |
| 116 | // |
| 117 | //#[bench] |
| 118 | //fn bench_small_init(b: &mut Bencher) -> Result<()> { |
| 119 | // b.iter(|| { |
| 120 | // test::black_box( |
| 121 | // vec![FILL_U8; SMALL_LEN] |
| 122 | // ); |
| 123 | // }); |
| 124 | // Ok(()) |
| 125 | //} |
| 126 | // |
| 127 | //#[bench] |
| 128 | //fn bench_large_init(b: &mut Bencher) -> Result<()> { |
| 129 | // b.iter(|| { |
| 130 | // test::black_box( |
| 131 | // vec![FILL_U8; LARGE_LEN] |
| 132 | // ); |
| 133 | // }); |
| 134 | // Ok(()) |
| 135 | //} |
| 136 | // |
| 137 | //#[bench] |
| 138 | //fn bench_u8_to_bytes_small(b: &mut Bencher) -> Result<()> { |
| 139 | // b.iter(|| { |
| 140 | // test::black_box( |
| 141 | // u8_to_bytes(FILL_U8, &mut vec![FILL_U8; SMALL_LEN]) |
| 142 | // ); |
| 143 | // }); |
| 144 | // Ok(()) |
| 145 | //} |
| 146 | // |
| 147 | //#[bench] |
| 148 | //fn bench_u8_to_bytes2_small(b: &mut Bencher) -> Result<()> { |
| 149 | // b.iter(|| { |
| 150 | // test::black_box( |
| 151 | // u8_to_bytes2(FILL_U8, vec![FILL_U8; SMALL_LEN]) |
| 152 | // ); |
| 153 | // }); |
| 154 | // Ok(()) |
| 155 | //} |
| 156 | // |
| 157 | //#[bench] |
| 158 | //fn bench_u64_to_bytes_small(b: &mut Bencher) -> Result<()> { |
| 159 | // b.iter(|| { |
| 160 | // test::black_box( |
| 161 | // u64_to_bytes(FILL_U64, &mut vec![FILL_U8; SMALL_LEN]) |
| 162 | // ); |
| 163 | // }); |
| 164 | // Ok(()) |
| 165 | //} |
| 166 | // |
| 167 | //#[bench] |
| 168 | //fn bench_u64_to_bytes2_small(b: &mut Bencher) -> Result<()> { |
| 169 | // b.iter(|| { |
| 170 | // test::black_box( |
| 171 | // u64_to_bytes2(FILL_U64, vec![FILL_U8; SMALL_LEN]) |
| 172 | // ); |
| 173 | // }); |
| 174 | // Ok(()) |
| 175 | //} |
| 176 | // |
| 177 | //#[bench] |
| 178 | //fn bench_u8_to_bytes_large(b: &mut Bencher) -> Result<()> { |
| 179 | // b.iter(|| { |
| 180 | // test::black_box( |
| 181 | // u8_to_bytes(FILL_U8, &mut vec![FILL_U8; LARGE_LEN]) |
| 182 | // ); |
| 183 | // }); |
| 184 | // Ok(()) |
| 185 | //} |
| 186 | // |
| 187 | //#[bench] |
| 188 | //fn bench_u8_to_bytes2_large(b: &mut Bencher) -> Result<()> { |
| 189 | // b.iter(|| { |
| 190 | // test::black_box( |
| 191 | // u8_to_bytes2(FILL_U8, vec![FILL_U8; LARGE_LEN]) |
| 192 | // ); |
| 193 | // }); |
| 194 | // Ok(()) |
| 195 | //} |
| 196 | // |
| 197 | //#[bench] |
| 198 | //fn bench_u64_to_bytes_large(b: &mut Bencher) -> Result<()> { |
| 199 | // b.iter(|| { |
| 200 | // test::black_box( |
| 201 | // u64_to_bytes(FILL_U64, &mut vec![FILL_U8; LARGE_LEN]) |
| 202 | // ); |
| 203 | // }); |
| 204 | // Ok(()) |
| 205 | //} |
| 206 | // |
| 207 | //#[bench] |
| 208 | //fn bench_u64_to_bytes2_large(b: &mut Bencher) -> Result<()> { |
| 209 | // b.iter(|| { |
| 210 | // test::black_box( |
| 211 | // u64_to_bytes2(FILL_U64, vec![FILL_U8; LARGE_LEN]) |
| 212 | // ); |
| 213 | // }); |
| 214 | // Ok(()) |
| 215 | //} |
| 216 | // |
| 217 | //#[bench] |
| 218 | //fn bench_u64_to_bytes3_large(b: &mut Bencher) -> Result<()> { |
| 219 | // b.iter(|| { |
| 220 | // test::black_box( |
| 221 | // u64_to_bytes3(FILL_U64, &mut vec![FILL_U8; LARGE_LEN]) |
| 222 | // ); |
| 223 | // }); |
| 224 | // Ok(()) |
| 225 | //} |
| 226 | // |
| 227 | //#[bench] |
| 228 | //fn bench_u64_to_bytes4_large(b: &mut Bencher) -> Result<()> { |
| 229 | // b.iter(|| { |
| 230 | // test::black_box( |
| 231 | // u64_to_bytes4(FILL_U64, vec![FILL_U8; LARGE_LEN]) |
| 232 | // ); |
| 233 | // }); |
| 234 | // Ok(()) |
| 235 | //} |
| 236 | // |
| 237 | //#[bench] |
| 238 | //fn bench_daticle_bytes_small(b: &mut Bencher) -> Result<()> { |
| 239 | // b.iter(|| { |
| 240 | // test::black_box( |
| 241 | // daticle_bytes(&vec![FILL_U8; SMALL_LEN], &mut vec![FILL_U8; SMALL_LEN]) |
| 242 | // ); |
| 243 | // }); |
| 244 | // Ok(()) |
| 245 | //} |
| 246 | // |
| 247 | //#[bench] |
| 248 | //fn bench_daticle_bytes2_small(b: &mut Bencher) -> Result<()> { |
| 249 | // b.iter(|| { |
| 250 | // test::black_box( |
| 251 | // daticle_bytes2(vec![FILL_U8; SMALL_LEN], vec![FILL_U8; SMALL_LEN]) |
| 252 | // ); |
| 253 | // }); |
| 254 | // Ok(()) |
| 255 | //} |
| 256 | // |
| 257 | //#[bench] |
| 258 | //fn bench_daticle_bytes3_small(b: &mut Bencher) -> Result<()> { |
| 259 | // b.iter(|| { |
| 260 | // test::black_box( |
| 261 | // daticle_bytes3(&vec![FILL_U8; SMALL_LEN], &mut vec![FILL_U8; SMALL_LEN]) |
| 262 | // ); |
| 263 | // }); |
| 264 | // Ok(()) |
| 265 | //} |
| 266 | // |
| 267 | //#[bench] |
| 268 | //fn bench_daticle_bytes_large(b: &mut Bencher) -> Result<()> { |
| 269 | // b.iter(|| { |
| 270 | // test::black_box( |
| 271 | // daticle_bytes(&vec![FILL_U8; LARGE_LEN], &mut vec![FILL_U8; LARGE_LEN]) |
| 272 | // ); |
| 273 | // }); |
| 274 | // Ok(()) |
| 275 | //} |
| 276 | // |
| 277 | //#[bench] |
| 278 | //fn bench_daticle_bytes2_large(b: &mut Bencher) -> Result<()> { |
| 279 | // b.iter(|| { |
| 280 | // test::black_box( |
| 281 | // daticle_bytes2(vec![FILL_U8; LARGE_LEN], vec![FILL_U8; LARGE_LEN]) |
| 282 | // ); |
| 283 | // }); |
| 284 | // Ok(()) |
| 285 | //} |
| 286 | // |
| 287 | //#[bench] |
| 288 | //fn bench_daticle_bytes3_large(b: &mut Bencher) -> Result<()> { |
| 289 | // b.iter(|| { |
| 290 | // test::black_box( |
| 291 | // daticle_bytes3(&vec![FILL_U8; LARGE_LEN], &mut vec![FILL_U8; LARGE_LEN]) |
| 292 | // ); |
| 293 | // }); |
| 294 | // Ok(()) |
| 295 | //} |
| 296 | // |
| 297 | //#[bench] |
| 298 | //fn bench_wrap_bytes_small(b: &mut Bencher) -> Result<()> { |
| 299 | // b.iter(|| { |
| 300 | // test::black_box( |
| 301 | // wrap_bytes(&mut vec![FILL_U8; SMALL_LEN]) |
| 302 | // ); |
| 303 | // }); |
| 304 | // Ok(()) |
| 305 | //} |
| 306 | // |
| 307 | //#[bench] |
| 308 | //fn bench_wrap_bytes2_small(b: &mut Bencher) -> Result<()> { |
| 309 | // b.iter(|| { |
| 310 | // test::black_box( |
| 311 | // wrap_bytes2(vec![FILL_U8; SMALL_LEN]) |
| 312 | // ); |
| 313 | // }); |
| 314 | // Ok(()) |
| 315 | //} |
| 316 | // |
| 317 | // |
| 318 | //#[bench] |
| 319 | //fn bench_wrap_bytes_large(b: &mut Bencher) -> Result<()> { |
| 320 | // b.iter(|| { |
| 321 | // test::black_box( |
| 322 | // wrap_bytes(&mut vec![FILL_U8; LARGE_LEN]) |
| 323 | // ); |
| 324 | // }); |
| 325 | // Ok(()) |
| 326 | //} |
| 327 | // |
| 328 | //#[bench] |
| 329 | //fn bench_wrap_bytes2_large(b: &mut Bencher) -> Result<()> { |
| 330 | // b.iter(|| { |
| 331 | // test::black_box( |
| 332 | // wrap_bytes2(vec![FILL_U8; LARGE_LEN]) |
| 333 | // ); |
| 334 | // }); |
| 335 | // Ok(()) |
| 336 | //} |
| 337 | // |
| 338 | //fn vec_to_bytes(v: &Vec<Dat>, buf: &mut Vec<u8>) { |
| 339 | // let mut buf2 = Vec::new(); |
| 340 | // for item in v { |
| 341 | // item.to_bytes(&mut buf2); |
| 342 | // } |
| 343 | // buf.push(Dat::LIST_CODE); |
| 344 | // Dat::C64(buf2.len() as u64).to_bytes(buf); |
| 345 | // buf.extend_from_slice(&buf2); |
| 346 | //} |
| 347 | // |
| 348 | //fn vec_to_bytes2(v: &Vec<Dat>, mut buf: Vec<u8>) -> Vec<u8> { |
| 349 | // let mut buf2 = Vec::new(); |
| 350 | // for item in v { |
| 351 | // item.to_bytes(&mut buf2); |
| 352 | // } |
| 353 | // buf.push(Dat::LIST_CODE); |
| 354 | // Dat::C64(buf2.len() as u64).to_bytes(&mut buf); |
| 355 | // buf.append(&mut buf2); |
| 356 | // buf |
| 357 | //} |
| 358 | // |
| 359 | //#[bench] |
| 360 | //fn bench_encode_list(b: &mut Bencher) -> Result<()> { |
| 361 | // let v = vec![ listdat![ |
| 362 | // vec![42;1000], // 1 |
| 363 | // vec![42;1000], // 2 |
| 364 | // vec![42;1000], // 3 |
| 365 | // vec![42;1000], // 4 |
| 366 | // vec![42;1000], // 5 |
| 367 | // vec![42;1000], // 6 |
| 368 | // vec![42;1000], // 7 |
| 369 | // vec![42;1000], // 8 |
| 370 | // vec![42;1000], // 9 |
| 371 | // vec![42;1000], // 10 |
| 372 | // ]]; |
| 373 | // let mut buf = Vec::new(); |
| 374 | // b.iter(|| { |
| 375 | // test::black_box( |
| 376 | // vec_to_bytes(&v, &mut buf) |
| 377 | // ); |
| 378 | // }); |
| 379 | // Ok(()) |
| 380 | //} |
| 381 | // |
| 382 | //#[bench] |
| 383 | //fn bench_encode_list2(b: &mut Bencher) -> Result<()> { |
| 384 | // let v = vec![ listdat![ |
| 385 | // vec![42;1000], // 1 |
| 386 | // vec![42;1000], // 2 |
| 387 | // vec![42;1000], // 3 |
| 388 | // vec![42;1000], // 4 |
| 389 | // vec![42;1000], // 5 |
| 390 | // vec![42;1000], // 6 |
| 391 | // vec![42;1000], // 7 |
| 392 | // vec![42;1000], // 8 |
| 393 | // vec![42;1000], // 9 |
| 394 | // vec![42;1000], // 10 |
| 395 | // ]]; |
| 396 | // b.iter(|| { |
| 397 | // test::black_box( |
| 398 | // vec_to_bytes2(&v, Vec::new()) |
| 399 | // ); |
| 400 | // }); |
| 401 | // Ok(()) |
| 402 | //} |
| 403 | |
| 404 | fn test_vec() -> Vec<u8> { |
| 405 | vec![42; 200] |
| 406 | } |
| 407 | |
| 408 | #[bench] |
| 409 | fn bench_wrap_bytes_placebo(b: &mut Bencher) -> Result<()> { |
| 410 | b.iter(|| { |
| 411 | test::black_box( |
| 412 | test_vec() |
| 413 | ); |
| 414 | }); |
| 415 | Ok(()) |
| 416 | } |
| 417 | |
| 418 | #[bench] |
| 419 | fn bench_wrap_bytes2(b: &mut Bencher) -> Result<()> { |
| 420 | b.iter(|| { |
| 421 | test::black_box( |
| 422 | Dat::wrap_bytes2(test_vec()) |
| 423 | ); |
| 424 | }); |
| 425 | Ok(()) |
| 426 | } |
| 427 | |
| 428 | #[bench] |
| 429 | fn bench_wrap_bytes(b: &mut Bencher) -> Result<()> { |
| 430 | b.iter(|| { |
| 431 | test::black_box( |
| 432 | Dat::wrap_bytes(test_vec()) |
| 433 | ); |
| 434 | }); |
| 435 | Ok(()) |
| 436 | } |
| 437 | |
| 438 | #[bench] |
| 439 | fn bench_wrap_bytes_c64(b: &mut Bencher) -> Result<()> { |
| 440 | b.iter(|| { |
| 441 | test::black_box( |
| 442 | Dat::wrap_bytes_c64(test_vec()) |
| 443 | ); |
| 444 | }); |
| 445 | Ok(()) |
| 446 | } |