gpt4 book ai didi

c++ - CPU % 约为 "what can be done"而不是 "what is happening"是否正常?

转载 作者:行者123 更新时间:2023-11-28 05:09:06 24 4
gpt4 key购买 nike

我有这个函数,它在我的应用程序中被频繁调用:

void Envelope::Process(Voice &voice) {
VoiceParameters &voiceParameters = mVoiceParameters[voice.mIndex];

// control rate
if (voiceParameters.mControlRateIndex-- == 0) {
voiceParameters.mControlRateIndex = PLUG_CONTROL_RATE - 1;

DBGMSG("I'm entered");
}

// next phase
voiceParameters.mBlockStep += mRate;
voiceParameters.mStep += mRate;
}

此函数从不在 if 语句中输入(即我从未看到“我已输入”消息)。它占用 3% 的 CPU。

现在,如果我写这个函数:

void Envelope::Process(Voice &voice) {
VoiceParameters &voiceParameters = mVoiceParameters[voice.mIndex];

// control rate
if (voiceParameters.mControlRateIndex-- == 0) {
voiceParameters.mControlRateIndex = PLUG_CONTROL_RATE - 1;

DBGMSG("I'm entered");

// samples (as rest) between two "quantized by block" sections occurs in the prev or next section, by round (interpolation). latest samples will be ignored (>) or added (<)
if (mIsEnabled) {
// update value
voiceParameters.mValue = (voiceParameters.mBlockStartAmp + (voiceParameters.mBlockStep * voiceParameters.mBlockFraction));

// scale value
if (!mIsBipolar) {
voiceParameters.mValue = (voiceParameters.mValue + 1.0) / 2.0;
}
voiceParameters.mValue *= mAmount;
}
else {
voiceParameters.mValue = 0.0;
}

// connectors
mOutputConnector_CV.mPolyValue[voice.mIndex] = voiceParameters.mValue;
}

// next phase
voiceParameters.mBlockStep += mRate;
voiceParameters.mStep += mRate;
}

(这样做是一样的,因为插入的代码永远不会执行)CPU 提高 7%。

这是怎么回事?怎么会这样?

我在 Release(或 Tracer,没什么不同)模式下工作。

最佳答案

由于“未使用”的额外代码包含对 voiceParameters.mBlockStep 的读取,因此对其写入变得相关。编译器可以更自由地使用只写变量,甚至可能消除它们。但他们至少可以做的是重新排序此类写入。

关于c++ - CPU % 约为 "what can be done"而不是 "what is happening"是否正常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43890877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com