环境
CPU: FT2000+
OS: Ubuntu 20.04
GCC: 9.4.0
测试方法
使用不同的GCC编译器优化选项,比较代码的执行时间
// benchmark.cpp
#include <iostream>
#include <chrono>
#include <vector>
#include <cmath>
#include <arm_neon.h>
// 计时器工具类
class Timer {
std::chrono::high_resolution_clock::time_point start;
public:
Timer() : start(std::chrono::high_resolution_clock::now()) {
}
double elapsed() {
auto now = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::microseconds>(now - start).count() / 1000.0;
}
};
// 测试1:基础向量运算
void vectorAdd(const std::vector<float>& a, const std::vector&l