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.

123 lines
3.0 KiB

  1. // Copyright (C) 2013-2015 by Maxim Bublis <b@codemonkey.ru>
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining
  4. // a copy of this software and associated documentation files (the
  5. // "Software"), to deal in the Software without restriction, including
  6. // without limitation the rights to use, copy, modify, merge, publish,
  7. // distribute, sublicense, and/or sell copies of the Software, and to
  8. // permit persons to whom the Software is furnished to do so, subject to
  9. // the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be
  12. // included in all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. package uuid
  22. import (
  23. "testing"
  24. )
  25. func BenchmarkFromBytes(b *testing.B) {
  26. bytes := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
  27. for i := 0; i < b.N; i++ {
  28. FromBytes(bytes)
  29. }
  30. }
  31. func BenchmarkFromString(b *testing.B) {
  32. s := "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
  33. for i := 0; i < b.N; i++ {
  34. FromString(s)
  35. }
  36. }
  37. func BenchmarkFromStringUrn(b *testing.B) {
  38. s := "urn:uuid:6ba7b810-9dad-11d1-80b4-00c04fd430c8"
  39. for i := 0; i < b.N; i++ {
  40. FromString(s)
  41. }
  42. }
  43. func BenchmarkFromStringWithBrackets(b *testing.B) {
  44. s := "{6ba7b810-9dad-11d1-80b4-00c04fd430c8}"
  45. for i := 0; i < b.N; i++ {
  46. FromString(s)
  47. }
  48. }
  49. func BenchmarkNewV1(b *testing.B) {
  50. for i := 0; i < b.N; i++ {
  51. NewV1()
  52. }
  53. }
  54. func BenchmarkNewV2(b *testing.B) {
  55. for i := 0; i < b.N; i++ {
  56. NewV2(DomainPerson)
  57. }
  58. }
  59. func BenchmarkNewV3(b *testing.B) {
  60. for i := 0; i < b.N; i++ {
  61. NewV3(NamespaceDNS, "www.example.com")
  62. }
  63. }
  64. func BenchmarkNewV4(b *testing.B) {
  65. for i := 0; i < b.N; i++ {
  66. NewV4()
  67. }
  68. }
  69. func BenchmarkNewV5(b *testing.B) {
  70. for i := 0; i < b.N; i++ {
  71. NewV5(NamespaceDNS, "www.example.com")
  72. }
  73. }
  74. func BenchmarkMarshalBinary(b *testing.B) {
  75. u := NewV4()
  76. for i := 0; i < b.N; i++ {
  77. u.MarshalBinary()
  78. }
  79. }
  80. func BenchmarkMarshalText(b *testing.B) {
  81. u := NewV4()
  82. for i := 0; i < b.N; i++ {
  83. u.MarshalText()
  84. }
  85. }
  86. func BenchmarkUnmarshalBinary(b *testing.B) {
  87. bytes := []byte{0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8}
  88. u := UUID{}
  89. for i := 0; i < b.N; i++ {
  90. u.UnmarshalBinary(bytes)
  91. }
  92. }
  93. func BenchmarkUnmarshalText(b *testing.B) {
  94. bytes := []byte("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
  95. u := UUID{}
  96. for i := 0; i < b.N; i++ {
  97. u.UnmarshalText(bytes)
  98. }
  99. }
  100. var sink string
  101. func BenchmarkMarshalToString(b *testing.B) {
  102. u := NewV4()
  103. for i := 0; i < b.N; i++ {
  104. sink = u.String()
  105. }
  106. }