相关疑难解决方法(0)

为什么 __int128_t 在 x86-64 GCC 上比 long long 快?

这是我的测试代码:

#include <chrono>
#include <iostream>
#include <cstdlib>
using namespace std;

using ll = long long;

int main()
{
    __int128_t a, b;
    ll x, y;

    a = rand() + 10000000;
    b = rand() % 50000;
    auto t0 = chrono::steady_clock::now();
    for (int i = 0; i < 100000000; i++)
    {
        a += b;
        a /= b;
        b *= a;
        b -= a;
        a %= b;
    }
    cout << chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - t0).count() << ' '
         << (ll)a % 100000 << '\n';

    x = …
Run Code Online (Sandbox Code Playgroud)

c++ performance x86-64 cpu-architecture integer-division

43
推荐指数
2
解决办法
3808
查看次数