tuna-f1sh / cyme

List system USB buses and devices; a lib and modern cross-platform lsusb that attempts to maintain compatibility with, but also add new features
GNU General Public License v3.0
141 stars 7 forks source link

Name regex pattern icon type #22

Open tuna-f1sh opened 4 days ago

tuna-f1sh commented 4 days ago

Icon lookup based on Regex pattern match of device name. Useful for common devices with no common VIDPID like SD Card Reader included in DEFAULT_ICONS as part of this.

tuna-f1sh commented 1 day ago

Quick test with no many devices using hyperfine, the difference is negligible if measurable at all:

❯ hyperfine --warmup 3 'cyme --verbose' '$CARGO_TARGET_DIR/release/cyme --verbose'
Benchmark 1: cyme --verbose
  Time (mean ± σ):      73.1 ms ±  29.4 ms    [User: 15.0 ms, System: 14.1 ms]
  Range (min … max):    51.0 ms … 132.1 ms    46 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Benchmark 2: $CARGO_TARGET_DIR/release/cyme --verbose
  Time (mean ± σ):      75.6 ms ±  28.8 ms    [User: 15.5 ms, System: 14.3 ms]
  Range (min … max):    53.9 ms … 131.0 ms    43 runs

Summary
  cyme --verbose ran
    1.03 ± 0.57 times faster than $CARGO_TARGET_DIR/release/cyme --verbose
tuna-f1sh commented 1 day ago

More realistic to test with a dump so any variation in system profiling is eliminated:

❯ hyperfine -N --warmup 3 'cyme --from-json ./tests/data/cyme_libusb_merge_macos_tree.json' '/Users/john/.cargo/target/release/cyme --from-json ./tests/data/cyme_libusb_merge_macos_tree.json'
Benchmark 1: cyme --from-json ./tests/data/cyme_libusb_merge_macos_tree.json
  Time (mean ± σ):       3.3 ms ±   0.2 ms    [User: 1.7 ms, System: 0.9 ms]
  Range (min … max):     3.0 ms …   5.7 ms    738 runs

Benchmark 2: /Users/john/.cargo/target/release/cyme --from-json ./tests/data/cyme_libusb_merge_macos_tree.json
  Time (mean ± σ):       4.5 ms ±   0.3 ms    [User: 2.9 ms, System: 1.0 ms]
  Range (min … max):     4.2 ms …   7.0 ms    433 runs

Summary
  cyme --from-json ./tests/data/cyme_libusb_merge_macos_tree.json ran
    1.35 ± 0.12 times faster than /Users/john/.cargo/target/release/cyme --from-json ./tests/data/cyme_libusb_merge_macos_tree.json

So it costs around 35% with only one default Icon::Name. Sounds like a lot but in the grand scheme of things it's a ~ 2 ms hit. Relative to the system runs (~80 ms) I think the feature is worth it. I added a 'regex_icon' feature around it however so this default feature can be disabled - useful as a crate too in order to avoid added regex dependency. See full commit message: https://github.com/tuna-f1sh/cyme/pull/22/commits/143b744899ac6dd391a66b9decc41a66a853368a