all.rs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #[macro_use]
  2. extern crate bencher;
  3. extern crate idna;
  4. use bencher::{black_box, Bencher};
  5. use idna::Config;
  6. fn to_unicode_puny_label(bench: &mut Bencher) {
  7. let encoded = "abc.xn--mgbcm";
  8. let config = Config::default();
  9. bench.iter(|| config.to_unicode(black_box(encoded)));
  10. }
  11. fn to_unicode_ascii(bench: &mut Bencher) {
  12. let encoded = "example.com";
  13. let config = Config::default();
  14. bench.iter(|| config.to_unicode(black_box(encoded)));
  15. }
  16. fn to_unicode_merged_label(bench: &mut Bencher) {
  17. let encoded = "Beispiel.xn--vermgensberater-ctb";
  18. let config = Config::default();
  19. bench.iter(|| config.to_unicode(black_box(encoded)));
  20. }
  21. fn to_ascii_puny_label(bench: &mut Bencher) {
  22. let encoded = "abc.ابج";
  23. let config = Config::default();
  24. bench.iter(|| config.to_ascii(black_box(encoded)));
  25. }
  26. fn to_ascii_simple(bench: &mut Bencher) {
  27. let encoded = "example.com";
  28. let config = Config::default();
  29. bench.iter(|| config.to_ascii(black_box(encoded)));
  30. }
  31. fn to_ascii_merged(bench: &mut Bencher) {
  32. let encoded = "beispiel.vermögensberater";
  33. let config = Config::default();
  34. bench.iter(|| config.to_ascii(black_box(encoded)));
  35. }
  36. benchmark_group!(
  37. benches,
  38. to_unicode_puny_label,
  39. to_unicode_ascii,
  40. to_unicode_merged_label,
  41. to_ascii_puny_label,
  42. to_ascii_simple,
  43. to_ascii_merged,
  44. );
  45. benchmark_main!(benches);