You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use bytes instead of strings, and slice in-place filter
(see https://github.com/golang/go/wiki/SliceTricks#filter-in-place)
to avoid copying strings around.
In my benchmark it shows almost 2x improvement:
BenchmarkString-8 1477207 10198 ns/op
BenchmarkBuffer-8 1561291 7622 ns/op
BenchmarkInPlace-8 2295714 5202 ns/op
String is the original implementation, Buffer is an intermediary
one that uses strings.Builder, and InPlace is the one from this commit.
Signed-off-by: Kir Kolyshkin <[email protected]>
Copy file name to clipboardExpand all lines: test/e2e/framework/log.go
+14-9Lines changed: 14 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -17,10 +17,10 @@ limitations under the License.
17
17
package framework
18
18
19
19
import (
20
+
"bytes"
20
21
"fmt"
21
22
"regexp"
22
23
"runtime/debug"
23
-
"strings"
24
24
"time"
25
25
26
26
"github.com/onsi/ginkgo"
@@ -78,12 +78,14 @@ var codeFilterRE = regexp.MustCompile(`/github.com/onsi/ginkgo/`)
78
78
// This is a modified copy of PruneStack in https://github.com/onsi/ginkgo/blob/f90f37d87fa6b1dd9625e2b1e83c23ffae3de228/internal/codelocation/code_location.go#L25:
79
79
// - simplified API and thus renamed (calls debug.Stack() instead of taking a parameter)
80
80
// - source code filtering updated to be specific to Kubernetes
81
-
funcPrunedStack(skipint) string {
82
-
fullStackTrace:=string(debug.Stack())
83
-
stack:=strings.Split(fullStackTrace, "\n")
81
+
// - optimized to use bytes and in-place slice filtering from
0 commit comments