首页 > 解决方案 > C#define 中的常数公式是否会影响效率?

问题描述

我正在阅读一些内核源代码cpufreq_governor.h并看到了这个:

/*
 * The polling frequency depends on the capability of the processor. Default
 * polling frequency is 1000 times the transition latency of the processor. The
 * governor will work on any processor with transition latency <= 10ms, using
 * appropriate sampling rate.
 *
 * For CPUs with transition latency > 10ms (mostly drivers with CPUFREQ_ETERNAL)
 * this governor will not work. All times here are in us (micro seconds).
 */
#define MIN_SAMPLING_RATE_RATIO         (2)
#define LATENCY_MULTIPLIER          (1000)
#define MIN_LATENCY_MULTIPLIER          (20)
#define TRANSITION_LATENCY_LIMIT        (10 * 1000 * 1000)

将最后一行更改为:

#define TRANSITION_LATENCY_LIMIT        (10000000) /* (10 * 1000 * 1000) */

标签: cc-preprocessor

解决方案


将最后一行更改为:

#define TRANSITION_LATENCY_LIMIT        (10000000) /* (10 * 1000 * 1000) */

很可能不会有任何区别。

任何半体面的编译器都应该能够10 * 1000 * 1000在编译时进行计算。


推荐阅读