Golang 程序性能分析:runtime.gopark 函数占主导地位

以下是 Golang 程序的性能消耗情况分析结果:

| flat | flat% | sum% | cum | cum% | 函数名 | |-------|---------|---------|-------|-------------------|---------------------------------| | 126 | 96.18% | 96.18% | 126 | 96.18% | runtime.gopark | | 1 | 0.76% | 96.95% | 1 | 0.76% | regexp.(*inputString).step | | 1 | 0.76% | 97.71% | 1 | 0.76% | regexp.(*machine).add | | 1 | 0.76% | 98.47% | 1 | 0.76% | regexp/syntax.(*Inst).MatchRunePos | | 1 | 0.76% | 99.24% | 1 | 0.76% | runtime.goroutineProfileWithLabels | | 1 | 0.76% | 100% | 1 | 0.76% | runtime.notetsleepg |

从分析结果可以看出:

  • 总共有 126 个调用被记录下来,其中最耗费性能的是 'runtime.gopark' 函数,占据了总耗时的 96.18%。
  • 其他耗费性能较多的函数包括 'regexp.(*inputString).step'、'regexp.(*machine).add'、'regexp/syntax.(*Inst).MatchRunePos' 和 'runtime.goroutineProfileWithLabels',它们分别占据了 0.76% 的总耗时。
  • 最后,'runtime.notetsleepg' 函数占据了总耗时的 0.76%。

可以看出,大部分性能消耗都集中在 'runtime.gopark' 函数上,因此优化该函数可能会明显提升程序的性能。其他耗费性能较多的函数也可以逐一进行优化。

Golang 程序性能分析:runtime.gopark 函数占主导地位

原文地址: https://www.cveoy.top/t/topic/nMbh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录