mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-01 05:08:58 +00:00
Unfortunately, we can't completely remove the ctx from git.Repository, because the CatFileBatch still heavily depends on a parent context. If we remove the Repository ctx, the CatFileBatch will become a mess and create a lot of unnecessary git processes. http://localhost:3000/-/admin/monitor/perftrace * Before: open a repo home, dozens of git processes (duplicate cat-file) * After: only a few (no duplicate cat-file)
33 lines
764 B
Go
33 lines
764 B
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCallerFuncName(t *testing.T) {
|
|
s := CallerFuncName()
|
|
assert.Equal(t, "util.TestCallerFuncName", s)
|
|
}
|
|
|
|
func BenchmarkCallerFuncName(b *testing.B) {
|
|
// BenchmarkCaller/sprintf-12 12744829 95.49 ns/op
|
|
b.Run("sprintf", func(b *testing.B) {
|
|
for b.Loop() {
|
|
_ = fmt.Sprintf("aaaaaaaaaaaaaaaa %s %s %s", "bbbbbbbbbbbbbbbbbbb", b.Name(), "ccccccccccccccccccccc")
|
|
}
|
|
})
|
|
// BenchmarkCaller/caller-12 10625133 113.6 ns/op
|
|
// It is almost as fast as fmt.Sprintf
|
|
b.Run("caller", func(b *testing.B) {
|
|
for b.Loop() {
|
|
CallerFuncName()
|
|
}
|
|
})
|
|
}
|