all.rs 1.6 KB

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