You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
1.7 KiB

  1. package idvalidator
  2. import (
  3. "testing"
  4. )
  5. func BenchmarkIsValid(b *testing.B) {
  6. benchmarks := []struct {
  7. name string
  8. id string
  9. }{
  10. {id: "440308199901101512"},
  11. {id: "610104620927690"},
  12. {id: "810000199408230021"},
  13. {id: "830000199201300022"},
  14. }
  15. for _, bm := range benchmarks {
  16. b.Run(bm.name, func(b *testing.B) {
  17. for i := 0; i < b.N; i++ {
  18. IsValid(bm.name)
  19. }
  20. })
  21. }
  22. }
  23. func BenchmarkGetInfo(b *testing.B) {
  24. benchmarks := []struct {
  25. name string
  26. id string
  27. }{
  28. {id: "440308199901101512"},
  29. {id: "610104620927690"},
  30. {id: "810000199408230021"},
  31. {id: "830000199201300022"},
  32. }
  33. for _, bm := range benchmarks {
  34. b.Run(bm.name, func(b *testing.B) {
  35. for i := 0; i < b.N; i++ {
  36. GetInfo(bm.name)
  37. }
  38. })
  39. }
  40. }
  41. func BenchmarkFakeId(b *testing.B) {
  42. for i := 0; i < b.N; i++ {
  43. FakeId()
  44. }
  45. }
  46. func BenchmarkFakeRequireId(b *testing.B) {
  47. benchmarks := []struct {
  48. name string
  49. isEighteen bool
  50. address string
  51. birthday string
  52. sex int
  53. }{
  54. {isEighteen: false, address: "浙江省", birthday: "20000101", sex: 1},
  55. {isEighteen: true, address: "浙江省", birthday: "20000101", sex: 0},
  56. {isEighteen: true, address: "台湾省", birthday: "20000101", sex: 0},
  57. {isEighteen: true, address: "香港特别行政区", birthday: "20000101", sex: 0},
  58. }
  59. for _, bm := range benchmarks {
  60. b.Run(bm.name, func(b *testing.B) {
  61. for i := 0; i < b.N; i++ {
  62. FakeRequireId(bm.isEighteen, bm.address, bm.birthday, bm.sex)
  63. }
  64. })
  65. }
  66. }
  67. func BenchmarkUpgradeId(b *testing.B) {
  68. benchmarks := []struct {
  69. name string
  70. id string
  71. }{
  72. {id: "610104620927690"},
  73. {id: "61010462092769"},
  74. }
  75. for _, bm := range benchmarks {
  76. b.Run(bm.name, func(b *testing.B) {
  77. for i := 0; i < b.N; i++ {
  78. UpgradeId(bm.id)
  79. }
  80. })
  81. }
  82. }