Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added

- Add `ByteSlice` and `ByteSliceValue` functions for new `BYTESLICE` attribute type in `go.opentelemetry.io/otel/attribute`. (#7948)
- Add `String` method for `Value` type in `go.opentelemetry.io/otel/attribute`. (#8142)
- Add `Error` field on `Record` type in `go.opentelemetry.io/otel/log/logtest`. (#8148)

### Changed
Expand Down
20 changes: 20 additions & 0 deletions attribute/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func benchmarkEmit(kv attribute.KeyValue) func(*testing.B) {
}
}

func benchmarkString(kv attribute.KeyValue) func(*testing.B) {
return func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
outStr = kv.Value.String()
}
}
}

func BenchmarkBool(b *testing.B) {
k, v := "bool", true
kv := attribute.Bool(k, v)
Expand All @@ -56,6 +65,7 @@ func BenchmarkBool(b *testing.B) {
outBool = kv.Value.AsBool()
}
})
b.Run("String", benchmarkString(kv))
b.Run("Emit", benchmarkEmit(kv))
}

Expand Down Expand Up @@ -89,6 +99,7 @@ func BenchmarkBoolSlice(b *testing.B) {
outBoolSlice = kv.Value.AsBoolSlice()
}
})
b.Run("String", benchmarkString(kv))
b.Run("Emit", benchmarkEmit(kv))
})
}
Expand All @@ -110,6 +121,7 @@ func BenchmarkInt(b *testing.B) {
outKV = attribute.Int(k, v)
}
})
b.Run("String", benchmarkString(kv))
b.Run("Emit", benchmarkEmit(kv))
}

Expand Down Expand Up @@ -137,6 +149,7 @@ func BenchmarkIntSlice(b *testing.B) {
outKV = attribute.IntSlice(k, v)
}
})
b.Run("String", benchmarkString(kv))
b.Run("Emit", benchmarkEmit(kv))
})
}
Expand Down Expand Up @@ -164,6 +177,7 @@ func BenchmarkInt64(b *testing.B) {
outInt64 = kv.Value.AsInt64()
}
})
b.Run("String", benchmarkString(kv))
b.Run("Emit", benchmarkEmit(kv))
}

Expand Down Expand Up @@ -197,6 +211,7 @@ func BenchmarkInt64Slice(b *testing.B) {
outInt64Slice = kv.Value.AsInt64Slice()
}
})
b.Run("String", benchmarkString(kv))
b.Run("Emit", benchmarkEmit(kv))
})
}
Expand Down Expand Up @@ -224,6 +239,7 @@ func BenchmarkFloat64(b *testing.B) {
outFloat64 = kv.Value.AsFloat64()
}
})
b.Run("String", benchmarkString(kv))
b.Run("Emit", benchmarkEmit(kv))
}

Expand Down Expand Up @@ -257,6 +273,7 @@ func BenchmarkFloat64Slice(b *testing.B) {
outFloat64Slice = kv.Value.AsFloat64Slice()
}
})
b.Run("String", benchmarkString(kv))
b.Run("Emit", benchmarkEmit(kv))
})
}
Expand Down Expand Up @@ -284,6 +301,7 @@ func BenchmarkString(b *testing.B) {
outStr = kv.Value.AsString()
}
})
b.Run("String", benchmarkString(kv))
b.Run("Emit", benchmarkEmit(kv))
}

Expand Down Expand Up @@ -317,6 +335,7 @@ func BenchmarkStringSlice(b *testing.B) {
outStrSlice = kv.Value.AsStringSlice()
}
})
b.Run("String", benchmarkString(kv))
b.Run("Emit", benchmarkEmit(kv))
})
}
Expand Down Expand Up @@ -347,6 +366,7 @@ func BenchmarkByteSlice(b *testing.B) {
}
})

b.Run("String", benchmarkString(kv))
b.Run("Emit", benchmarkEmit(kv))
}

Expand Down
Loading
Loading