all.rs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_ascii_already_puny_label(bench: &mut Bencher) {
  12. let encoded = "abc.xn--mgbcm";
  13. let config = Config::default();
  14. bench.iter(|| config.to_ascii(black_box(encoded)));
  15. }
  16. fn to_unicode_ascii(bench: &mut Bencher) {
  17. let encoded = "example.com";
  18. let config = Config::default();
  19. bench.iter(|| config.to_unicode(black_box(encoded)));
  20. }
  21. fn to_unicode_merged_label(bench: &mut Bencher) {
  22. let encoded = "Beispiel.xn--vermgensberater-ctb";
  23. let config = Config::default();
  24. bench.iter(|| config.to_unicode(black_box(encoded)));
  25. }
  26. fn to_ascii_puny_label(bench: &mut Bencher) {
  27. let encoded = "abc.ابج";
  28. let config = Config::default();
  29. bench.iter(|| config.to_ascii(black_box(encoded)));
  30. }
  31. fn to_ascii_simple(bench: &mut Bencher) {
  32. let encoded = "example.com";
  33. let config = Config::default();
  34. bench.iter(|| config.to_ascii(black_box(encoded)));
  35. }
  36. fn to_ascii_merged(bench: &mut Bencher) {
  37. let encoded = "beispiel.vermögensberater";
  38. let config = Config::default();
  39. bench.iter(|| config.to_ascii(black_box(encoded)));
  40. }
  41. benchmark_group!(
  42. benches,
  43. to_unicode_puny_label,
  44. to_unicode_ascii,
  45. to_unicode_merged_label,
  46. to_ascii_puny_label,
  47. to_ascii_already_puny_label,
  48. to_ascii_simple,
  49. to_ascii_merged,
  50. );
  51. benchmark_main!(benches);