From eaa34817d0a04e90321b166a0842186e6704b987 Mon Sep 17 00:00:00 2001 From: Lomanic Date: Wed, 30 Sep 2020 00:00:10 +0200 Subject: [PATCH] [process] Add benchmarks for New(), Name() Ppid() run only them with: go test -bench=. -run=xxx github.com/shirou/gopsutil/process --- process/process_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/process/process_test.go b/process/process_test.go index e18a26d..28518b8 100644 --- a/process/process_test.go +++ b/process/process_test.go @@ -662,3 +662,24 @@ func Test_AllProcesses_cmdLine(t *testing.T) { } } } + +func BenchmarkNewProcess(b *testing.B) { + checkPid := os.Getpid() + for i := 0; i < b.N; i++ { + NewProcess(int32(checkPid)) + } +} + +func BenchmarkProcessName(b *testing.B) { + p := testGetProcess() + for i := 0; i < b.N; i++ { + p.Name() + } +} + +func BenchmarkProcessPpid(b *testing.B) { + p := testGetProcess() + for i := 0; i < b.N; i++ { + p.Ppid() + } +}