https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118072

mcccs at gmx dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mcccs at gmx dot com

--- Comment #5 from mcccs at gmx dot com ---
Yes, they are very close.

> Function 1 took 2304345 microseconds
> Function 2 took 2304357 microseconds

Other runs output similar values.

for the code:

#include <iostream>
#include <chrono>

__attribute__((noipa)) void g(int r) {(void) r;}

__attribute__((noipa)) unsigned long mod7(unsigned long n) {
  return n % 7;
}
__attribute__((noipa)) unsigned long div7(unsigned long n) {
  return n / 7;
}
__attribute__((noipa)) unsigned long mod7_1(unsigned long n) {
  return n % 7;
}

// Function 1 to benchmark
void function1() {
    // Simulate some work
    for (long i = (1l << 50); i < (1l << 50)+ 1000000000; i++) {
        g(mod7(i));
    }
}

// Function 2 to benchmark
void function2() {
    // Simulate some work
    for (long i = (1l << 50); i < (1l << 50)+ 1000000000; i++) {
        g(mod7_1(i));
    }
}

// Benchmark function
template <typename Func>
auto benchmark(Func func) {
    auto start = std::chrono::high_resolution_clock::now();
    func();
    auto end = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end -
start);
    return duration.count();
}

int main() {
    g(mod7(1l << 50));
    g(mod7_1(1l << 50));
    // Benchmark function1
    auto time1 = benchmark(function1);
    std::cout << "Function 1 took " << time1 << " microseconds" << std::endl;

    // Benchmark function2
    auto time2 = benchmark(function2);
    std::cout << "Function 2 took " << time2 << " microseconds" << std::endl;

    return 0;
}

Reply via email to