我正在尝试找到一种比常规乘法更快的方法。我在 vscode 中运行代码,据我所知,我没有启用优化。我也尝试过gcc -O0 _.c -o _但仍然得到相同的结果。我还在 M0 Assembly 中编写了相同的代码,但常规乘法又是最快的。我是否遗漏了什么,也许是时间计算,或者常规乘法真的是最快的方法?
#include <stdio.h>
#include <time.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int max(int a, int b) {
return (a > b) ? a : b;
}
uint64_t karatsuba(uint64_t x, uint64_t y) {
if (x < 10 || y < 10) {
return x * y;
}
int n = max(log10(x) + 1, log10(y) + 1) / 2;
uint64_t a = x / (uint64_t)pow(10, n);
uint64_t b = …Run Code Online (Sandbox Code Playgroud)