all.rs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. fn to_ascii_cow_plain(bench: &mut Bencher) {
  43. let encoded = "example.com".as_bytes();
  44. bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
  45. }
  46. fn to_ascii_cow_hyphen(bench: &mut Bencher) {
  47. let encoded = "hyphenated-example.com".as_bytes();
  48. bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
  49. }
  50. fn to_ascii_cow_leading_digit(bench: &mut Bencher) {
  51. let encoded = "1test.example".as_bytes();
  52. bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
  53. }
  54. fn to_ascii_cow_unicode_mixed(bench: &mut Bencher) {
  55. let encoded = "مثال.example".as_bytes();
  56. bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
  57. }
  58. fn to_ascii_cow_punycode_mixed(bench: &mut Bencher) {
  59. let encoded = "xn--mgbh0fb.example".as_bytes();
  60. bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
  61. }
  62. fn to_ascii_cow_unicode_ltr(bench: &mut Bencher) {
  63. let encoded = "නම.උදාහරණ".as_bytes();
  64. bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
  65. }
  66. fn to_ascii_cow_punycode_ltr(bench: &mut Bencher) {
  67. let encoded = "xn--r0co.xn--ozc8dl2c3bxd".as_bytes();
  68. bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
  69. }
  70. fn to_ascii_cow_unicode_rtl(bench: &mut Bencher) {
  71. let encoded = "الاسم.مثال".as_bytes();
  72. bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
  73. }
  74. fn to_ascii_cow_punycode_rtl(bench: &mut Bencher) {
  75. let encoded = "xn--mgba0b1dh.xn--mgbh0fb".as_bytes();
  76. bench.iter(|| idna::domain_to_ascii_cow(black_box(encoded), idna::AsciiDenyList::URL));
  77. }
  78. benchmark_group!(
  79. benches,
  80. to_unicode_puny_label,
  81. to_unicode_ascii,
  82. to_unicode_merged_label,
  83. to_ascii_puny_label,
  84. to_ascii_already_puny_label,
  85. to_ascii_simple,
  86. to_ascii_merged,
  87. to_ascii_cow_plain,
  88. to_ascii_cow_hyphen,
  89. to_ascii_cow_leading_digit,
  90. to_ascii_cow_unicode_mixed,
  91. to_ascii_cow_punycode_mixed,
  92. to_ascii_cow_unicode_ltr,
  93. to_ascii_cow_punycode_ltr,
  94. to_ascii_cow_unicode_rtl,
  95. to_ascii_cow_punycode_rtl,
  96. );
  97. benchmark_main!(benches);