Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmark for ctags conversion #679

Merged
merged 3 commits into from
Nov 6, 2023
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
4 changes: 2 additions & 2 deletions build/ctags.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func overlaps(symOffsets []zoekt.DocumentSection, start, end uint32) int {
func tagsToSections(content []byte, tags []*ctags.Entry) ([]zoekt.DocumentSection, []*zoekt.Symbol, error) {
nls := newLinesIndices(content)
nls = append(nls, uint32(len(content)))
var symOffsets []zoekt.DocumentSection
var symMetaData []*zoekt.Symbol
symOffsets := make([]zoekt.DocumentSection, 0, len(tags))
symMetaData := make([]*zoekt.Symbol, 0, len(tags))

for _, t := range tags {
if t.Line <= 0 {
Expand Down
37 changes: 37 additions & 0 deletions build/ctags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package build

import (
"os"
"reflect"
"testing"

Expand Down Expand Up @@ -229,3 +230,39 @@ func TestOverlaps(t *testing.T) {
})
}
}

func BenchmarkTagsToSections(b *testing.B) {
if checkCTags() == "" {
b.Skip("ctags not available")
}

file, err := os.ReadFile("./testdata/large_file.cc")
parser, err := ctags.NewParser(ctags.UniversalCTags, "universal-ctags")
if err != nil {
b.Fatal(err)
}

entries, err := parser.Parse("./testdata/large_file.cc", file)
if err != nil {
b.Fatal(err)
}

secs, _, err := tagsToSections(file, entries)
if err != nil {
b.Fatal(err)
}

if len(secs) != 439 {
b.Fatalf("got %d sections, want 439 sections", len(secs))
}

b.ResetTimer()
b.ReportAllocs()

for n := 0; n < b.N; n++ {
_, _, err := tagsToSections(file, entries)
if err != nil {
b.Fatal(err)
}
}
}
Loading
Loading