From 51152a0ea5eb36756bcaa0e4715bce8e155a1eb6 Mon Sep 17 00:00:00 2001 From: Eduardo Almeida Date: Wed, 6 Mar 2024 22:15:48 +0000 Subject: [PATCH] wifi: Avoid repeated calculations by caching result --- src/wifi/model/spectrum-wifi-phy.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wifi/model/spectrum-wifi-phy.cc b/src/wifi/model/spectrum-wifi-phy.cc index dbb5903c8..a4d8bc344 100644 --- a/src/wifi/model/spectrum-wifi-phy.cc +++ b/src/wifi/model/spectrum-wifi-phy.cc @@ -423,6 +423,8 @@ SpectrumWifiPhy::StartRx(Ptr rxParams, double totalRxPowerW = 0; RxPowerWattPerChannelBand rxPowerW; + const auto rxGainRatio = DbToRatio(GetRxGain()); + std::size_t index = 0; uint16_t prevBw = 0; for (const auto& band : bands) @@ -434,7 +436,7 @@ SpectrumWifiPhy::StartRx(Ptr rxParams, WifiSpectrumValueHelper::GetBandPowerW(receivedSignalPsd, band.indices); NS_LOG_DEBUG("Signal power received (watts) before antenna gain for " << bw << " MHz channel band " << index << ": " << band); - rxPowerPerBandW *= DbToRatio(GetRxGain()); + rxPowerPerBandW *= rxGainRatio; rxPowerW.insert({band, rxPowerPerBandW}); NS_LOG_DEBUG("Signal power received after antenna gain for " << bw << " MHz channel band " << index << ": " << rxPowerPerBandW << " W (" @@ -459,7 +461,7 @@ SpectrumWifiPhy::StartRx(Ptr rxParams, << ru.GetRuType() << " and index " << ru.GetIndex() << " -> (" << band.indices.first << "; " << band.indices.second << "): " << rxPowerPerBandW); - rxPowerPerBandW *= DbToRatio(GetRxGain()); + rxPowerPerBandW *= rxGainRatio; NS_LOG_DEBUG("Signal power received after antenna gain for RU with type " << ru.GetRuType() << " and index " << ru.GetIndex() << " -> (" << band.indices.first << "; " << band.indices.second << "): "