相关疑难解决方法(0)

无符号与有符号整数的性能

通过在有符号整数上使用无符号整数,是否有任何性能增益/损失?

如果是这样,这也是短期和长期的吗?

c c++ int unsigned integer

67
推荐指数
7
解决办法
3万
查看次数

在C中,为什么"signed int"比"unsigned int"更快?

在C中,为什么signed int速度比unsigned int?是的,我知道这个网站已被多次询问和回答(链接如下).但是,大多数人说没有区别.我编写了代码并意外地发现了显着的性能差异.

为什么我的代码的"未签名"版本比"签名"版本慢(即使在测试相同的数字时)?(我有一个x86-64英特尔处理器).

类似的链接

编译命令: gcc -Wall -Wextra -pedantic -O3 -Wl,-O3 -g0 -ggdb0 -s -fwhole-program -funroll-loops -pthread -pipe -ffunction-sections -fdata-sections -std=c11 -o ./test ./test.c && strip --strip-all --strip-unneeded --remove-section=.note --remove-section=.comment ./test


signed int

注意:如果我明确声明signed int所有数字,则没有区别.

int isprime(int num) {
    // Test if a signed int is prime
    int i;
    if (num % 2 == 0 || num % 3 == 0)
        return 0;
    else if (num % 5 == …
Run Code Online (Sandbox Code Playgroud)

c optimization performance unsigned signed

30
推荐指数
3
解决办法
4672
查看次数

标签 统计

c ×2

unsigned ×2

c++ ×1

int ×1

integer ×1

optimization ×1

performance ×1

signed ×1