Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

97 righe
2.3 KiB

  1. // Copyright 2017, OpenCensus Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package stats_test
  15. import (
  16. "context"
  17. "testing"
  18. "go.opencensus.io/stats"
  19. _ "go.opencensus.io/stats/view" // enable collection
  20. "go.opencensus.io/tag"
  21. )
  22. var m = makeMeasure()
  23. func BenchmarkRecord0(b *testing.B) {
  24. ctx := context.Background()
  25. b.ResetTimer()
  26. for i := 0; i < b.N; i++ {
  27. stats.Record(ctx)
  28. }
  29. }
  30. func BenchmarkRecord1(b *testing.B) {
  31. ctx := context.Background()
  32. b.ResetTimer()
  33. for i := 0; i < b.N; i++ {
  34. stats.Record(ctx, m.M(1))
  35. }
  36. }
  37. func BenchmarkRecord8(b *testing.B) {
  38. ctx := context.Background()
  39. b.ResetTimer()
  40. for i := 0; i < b.N; i++ {
  41. stats.Record(ctx, m.M(1), m.M(1), m.M(1), m.M(1), m.M(1), m.M(1), m.M(1), m.M(1))
  42. }
  43. }
  44. func BenchmarkRecord8_Parallel(b *testing.B) {
  45. ctx := context.Background()
  46. b.ResetTimer()
  47. b.RunParallel(func(pb *testing.PB) {
  48. for pb.Next() {
  49. stats.Record(ctx, m.M(1), m.M(1), m.M(1), m.M(1), m.M(1), m.M(1), m.M(1), m.M(1))
  50. }
  51. })
  52. }
  53. func BenchmarkRecord8_8Tags(b *testing.B) {
  54. ctx := context.Background()
  55. key1, _ := tag.NewKey("key1")
  56. key2, _ := tag.NewKey("key2")
  57. key3, _ := tag.NewKey("key3")
  58. key4, _ := tag.NewKey("key4")
  59. key5, _ := tag.NewKey("key5")
  60. key6, _ := tag.NewKey("key6")
  61. key7, _ := tag.NewKey("key7")
  62. key8, _ := tag.NewKey("key8")
  63. tag.New(ctx,
  64. tag.Insert(key1, "value"),
  65. tag.Insert(key2, "value"),
  66. tag.Insert(key3, "value"),
  67. tag.Insert(key4, "value"),
  68. tag.Insert(key5, "value"),
  69. tag.Insert(key6, "value"),
  70. tag.Insert(key7, "value"),
  71. tag.Insert(key8, "value"),
  72. )
  73. b.ResetTimer()
  74. for i := 0; i < b.N; i++ {
  75. stats.Record(ctx, m.M(1), m.M(1), m.M(1), m.M(1), m.M(1), m.M(1), m.M(1), m.M(1))
  76. }
  77. }
  78. func makeMeasure() *stats.Int64Measure {
  79. return stats.Int64("m", "test measure", "")
  80. }