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.

benchmarks_test.go 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (C) 2013 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. }