Files
tsgo/internal/ast/utilities_bench_test.go

49 lines
1.3 KiB
Go

package ast_test
import (
"testing"
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/parser"
"github.com/microsoft/typescript-go/internal/testutil/fixtures"
"github.com/microsoft/typescript-go/internal/tspath"
"github.com/microsoft/typescript-go/internal/vfs/osvfs"
)
func BenchmarkGetCombinedFlags(b *testing.B) {
for _, f := range fixtures.BenchFixtures {
b.Run(f.Name(), func(b *testing.B) {
f.SkipIfNotExist(b)
fileName := tspath.GetNormalizedAbsolutePath(f.Path(), "/")
path := tspath.ToPath(fileName, "/", osvfs.FS().UseCaseSensitiveFileNames())
sourceText := f.ReadFile(b)
scriptKind := core.GetScriptKindFromFileName(fileName)
sourceFile := parser.ParseSourceFile(ast.SourceFileParseOptions{
FileName: fileName,
Path: path,
}, sourceText, scriptKind)
var decls []*ast.Node
var collect ast.Visitor
collect = func(n *ast.Node) bool {
if ast.IsDeclaration(n) {
decls = append(decls, n)
}
n.ForEachChild(collect)
return false
}
sourceFile.AsNode().ForEachChild(collect)
for b.Loop() {
for _, n := range decls {
_ = ast.GetCombinedNodeFlags(n)
_ = ast.GetCombinedModifierFlags(n)
}
}
})
}
}