Welcome to mirror list, hosted at ThFree Co, Russian Federation.

performance_test.go « parser « lsif_transformer « internal « workhorse - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 392fe2b6900d31d86ad3f1d92ce903ddeeea09d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package parser

import (
	"context"
	"io"
	"os"
	"runtime"
	"testing"

	"github.com/stretchr/testify/require"
)

func BenchmarkGenerate(b *testing.B) {
	filePath := "testdata/workhorse.lsif.zip"
	tmpDir := filePath + ".tmp"
	defer os.RemoveAll(tmpDir)

	var memoryUsage float64
	for i := 0; i < b.N; i++ {
		memoryUsage += measureMemory(func() {
			file, err := os.Open(filePath)
			require.NoError(b, err)

			parser, err := NewParser(context.Background(), file, Config{})
			require.NoError(b, err)

			_, err = io.Copy(io.Discard, parser)
			require.NoError(b, err)
			require.NoError(b, parser.Close())
		})
	}

	b.ReportMetric(memoryUsage/float64(b.N), "MiB/op")
}

func measureMemory(f func()) float64 {
	var m, m1 runtime.MemStats
	runtime.ReadMemStats(&m)

	f()

	runtime.ReadMemStats(&m1)
	runtime.GC()

	return float64(m1.Alloc-m.Alloc) / 1024 / 1024
}