为了账号安全,请及时绑定邮箱和手机立即绑定

为什么“MOVQ 0x30(SP), DX”慢?

为什么“MOVQ 0x30(SP), DX”慢?

Go
慕的地10843 2023-03-29 17:31:52
请参阅以下 pprof 会话。在 treesort.add 的第 42 行中,有一个 int 比较。我认为它占所有 cpu 时间的 64%。在 disasm 中,操作是“MOVQ 0x30(SP), DX”。为什么这么慢?File: treesort_bench.test.exeType: cpuTime: Sep 7, 2018 at 3:15pm (EDT)Duration: 2.60s, Total samples = 2.43s (93.44%)Entering interactive mode (type "help" for commands, "o" for options)(pprof) top 10Showing nodes accounting for 2.41s, 99.18% of 2.43s totalDropped 2 nodes (cum <= 0.01s)      flat  flat%   sum%        cum   cum%     2.40s 98.77% 98.77%      2.42s 99.59%  gopl.io/ch4/treesort.add     0.01s  0.41% 99.18%      0.02s  0.82%  runtime.mallocgc         0     0% 99.18%      0.26s 10.70%  gopl.io/ch4/treesort.Sort         0     0% 99.18%      0.25s 10.29%  gopl.io/ch4/treesort_bench.BenchmarkSort         0     0% 99.18%      0.26s 10.70%  gopl.io/ch4/treesort_bench.run         0     0% 99.18%      0.02s  0.82%  runtime.newobject         0     0% 99.18%      0.22s  9.05%  testing.(*B).launch         0     0% 99.18%      0.02s  0.82%  testing.(*B).run1.func1        0     0% 99.18%      0.25s 10.29%  testing.(*B).runN(pprof) list addTotal: 2.43sROUTINE ======================== gopl.io/ch4/treesort.add in go\src\gopl.io\ch4\treesort\sort.go     2.40s      4.45s (flat, cum) 183.13% of Total         .          .     30:           values = appendValues(values, t.right)         .          .     31:   }         .          .     32:   return values         .          .     33:}         .          .     34:      90ms       90ms     35:func add(t *tree, value int) *tree {         .          .     36:   if t == nil {         .          .     37:           // Equivalent to return &tree{value: value}.         .       20ms     38:           t = new(tree)         .          .     39:           t.value = value         .          .     40:           return t         .          .     41:   }
查看完整描述

1 回答

?
肥皂起泡泡

TA贡献1829条经验 获得超6个赞

为什么“MOVQ 0x30(SP), DX”慢?

您提供的证据不足以表明指令速度缓慢。


MOVQ — 移动四字 — 是来自 Intel 64 和 IA-32 架构指令集的指令。

MOVQ 0x30(SP), DX指令将变量的 8 个字节tree.value从内存移动到 DX 寄存器。


与任何其他科学努力一样,性能测量依赖于可重现的结果。您提供的信息不足以重现您的结果。例如,代码在哪里treesort_bench.test.exe,什么处理器,什么内存,什么操作系统?。

我试过了,但无法重现您的结果。将您的代码和重现结果的步骤添加到您的问题中。


查看完整回答
反对 回复 2023-03-29
  • 1 回答
  • 0 关注
  • 46 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信