github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/build/tar_benchmark_test.go (about) 1 package build 2 3 import ( 4 "bytes" 5 "context" 6 "fmt" 7 "path/filepath" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 12 "github.com/tilt-dev/tilt/internal/ignore" 13 "github.com/tilt-dev/tilt/internal/testutils/tempdir" 14 ) 15 16 func BenchmarkArchivePaths(b *testing.B) { 17 f := tempdir.NewTempDirFixture(b) 18 19 fileCount := 10000 20 for i := 0; i < fileCount; i++ { 21 dir := "dirA" 22 if i%2 == 0 { 23 dir = "dirB" 24 } 25 26 filename := fmt.Sprintf("file%d", i) 27 f.WriteFile(filepath.Join(dir, filename), "contents") 28 } 29 30 b.ResetTimer() 31 32 run := func() { 33 writer := &bytes.Buffer{} 34 filter, err := ignore.NewDirectoryMatcher(f.JoinPath(f.Path(), "dirA")) 35 assert.NoError(b, err) 36 37 builder := NewArchiveBuilder(writer, filter) 38 err = builder.ArchivePathsIfExist(context.Background(), []PathMapping{ 39 { 40 LocalPath: f.Path(), 41 ContainerPath: "/", 42 }, 43 }) 44 assert.NoError(b, err) 45 err = builder.Close() 46 assert.NoError(b, err) 47 } 48 for i := 0; i < b.N; i++ { 49 run() 50 } 51 }