Skip to content

Commit

Permalink
Add benchmark for ctags conversion (#679)
Browse files Browse the repository at this point in the history
This change adds a benchmark for the conversion from ctags output to Zoekt
document data, plus a tiny optimization to presize the symbol slices.
  • Loading branch information
jtibshirani authored Nov 6, 2023
1 parent 0ff0dd5 commit dc41c6e
Show file tree
Hide file tree
Showing 3 changed files with 4,696 additions and 2 deletions.
4 changes: 2 additions & 2 deletions build/ctags.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,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

0 comments on commit dc41c6e

Please sign in to comment.