gitea源码

runtime_test.go 794B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2024 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package util
  4. import (
  5. "fmt"
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestCallerFuncName(t *testing.T) {
  10. s := CallerFuncName(1)
  11. assert.Equal(t, "code.gitea.io/gitea/modules/util.TestCallerFuncName", s)
  12. }
  13. func BenchmarkCallerFuncName(b *testing.B) {
  14. // BenchmarkCaller/sprintf-12 12744829 95.49 ns/op
  15. b.Run("sprintf", func(b *testing.B) {
  16. for b.Loop() {
  17. _ = fmt.Sprintf("aaaaaaaaaaaaaaaa %s %s %s", "bbbbbbbbbbbbbbbbbbb", b.Name(), "ccccccccccccccccccccc")
  18. }
  19. })
  20. // BenchmarkCaller/caller-12 10625133 113.6 ns/op
  21. // It is almost as fast as fmt.Sprintf
  22. b.Run("caller", func(b *testing.B) {
  23. for b.Loop() {
  24. CallerFuncName(1)
  25. }
  26. })
  27. }