|
3 | 3 | extern crate test;
|
4 | 4 |
|
5 | 5 | use gimli::{
|
6 |
| - AttributeValue, DebugAbbrev, DebugAddr, DebugAddrBase, DebugAranges, DebugInfo, DebugLine, |
7 |
| - DebugLineOffset, DebugLoc, DebugLocLists, DebugPubNames, DebugPubTypes, DebugRanges, |
| 6 | + leb128, AttributeValue, DebugAbbrev, DebugAddr, DebugAddrBase, DebugAranges, DebugInfo, |
| 7 | + DebugLine, DebugLineOffset, DebugLoc, DebugLocLists, DebugPubNames, DebugPubTypes, DebugRanges, |
8 | 8 | DebugRngLists, Encoding, EndianSlice, EntriesTreeNode, Expression, LittleEndian, LocationLists,
|
9 |
| - Operation, RangeLists, RangeListsOffset, Reader, ReaderOffset, |
| 9 | + NativeEndian, Operation, RangeLists, RangeListsOffset, Reader, ReaderOffset, |
10 | 10 | };
|
11 | 11 | use std::env;
|
12 | 12 | use std::fs::File;
|
13 | 13 | use std::io::Read;
|
14 | 14 | use std::path::PathBuf;
|
15 | 15 | use std::rc::Rc;
|
16 | 16 |
|
| 17 | +#[bench] |
| 18 | +fn bench_reading_leb128_unsigned(b: &mut test::Bencher) { |
| 19 | + #[rustfmt::skip] |
| 20 | + let data = [ |
| 21 | + (&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01][..], u64::MAX), |
| 22 | + (&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00][..], u64::MAX / 2), |
| 23 | + (&[0xd5, 0xaa, 0xd5, 0xaa, 0xd5, 0xaa, 0xd5, 0xaa, 0x55, 0x00][..], u64::MAX / 3), |
| 24 | + (&[0xb3, 0xe6, 0xcc, 0x99, 0xb3, 0xe6, 0xcc, 0x99, 0x33, 0x00][..], u64::MAX / 5), |
| 25 | + (&[0xaa, 0xd5, 0xaa, 0xd5, 0xaa, 0xd5, 0xaa, 0xd5, 0x2a, 0x00][..], u64::MAX / 6), |
| 26 | + (&[0x92, 0xc9, 0xa4, 0x92, 0xc9, 0xa4, 0x92, 0xc9, 0x24, 0x00][..], u64::MAX / 7), |
| 27 | + (&[0xf1, 0xb8, 0x9c, 0x8e, 0xc7, 0xe3, 0xf1, 0xb8, 0x1c, 0x00][..], u64::MAX / 9), |
| 28 | + (&[0x99, 0xb3, 0xe6, 0xcc, 0x99, 0xb3, 0xe6, 0xcc, 0x19, 0x00][..], u64::MAX / 10), |
| 29 | + (&[0xd1, 0x8b, 0xdd, 0xe8, 0xc5, 0xae, 0xf4, 0xa2, 0x17, 0x00][..], u64::MAX / 11), |
| 30 | + (&[0xd5, 0xaa, 0xd5, 0xaa, 0xd5, 0xaa, 0xd5, 0xaa, 0x15, 0x00][..], u64::MAX / 12), |
| 31 | + (&[0xb1, 0xa7, 0xec, 0x89, 0xbb, 0xe2, 0xce, 0xd8, 0x13, 0x00][..], u64::MAX / 13), |
| 32 | + (&[0xc9, 0xa4, 0x92, 0xc9, 0xa4, 0x92, 0xc9, 0xa4, 0x12, 0x00][..], u64::MAX / 14), |
| 33 | + (&[0x91, 0xa2, 0xc4, 0x88, 0x91, 0xa2, 0xc4, 0x88, 0x11, 0x00][..], u64::MAX / 15), |
| 34 | + ]; |
| 35 | + |
| 36 | + for (data, expected) in data { |
| 37 | + let mut slice = test::black_box(EndianSlice::new(data, NativeEndian)); |
| 38 | + let v = leb128::read::unsigned(&mut slice).unwrap(); |
| 39 | + assert_eq!(v, expected); |
| 40 | + } |
| 41 | + |
| 42 | + let () = b.iter(|| { |
| 43 | + for (data, _) in data { |
| 44 | + let mut slice = test::black_box(EndianSlice::new(data, NativeEndian)); |
| 45 | + let v = leb128::read::unsigned(&mut slice).unwrap(); |
| 46 | + test::black_box(v); |
| 47 | + } |
| 48 | + }); |
| 49 | +} |
| 50 | + |
17 | 51 | pub fn read_section(section: &str) -> Vec<u8> {
|
18 | 52 | let mut path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".into()));
|
19 | 53 | path.push("./fixtures/self/");
|
|
0 commit comments