https://travisdowns.github.io/blog/2019/08/26/vector-inc.html
为什么vector<uint8_t>
每个元素++比vector<uint32_t>
慢
(unsigned char
和 char
可变长)
void vector8_inc(std::vector<uint8_t>& v) {
for (size_t i = 0; i < v.size(); i++) {
v[i]++;
}
}
void vector32_inc(std::vector<uint32_t>& v) {
for (size_t i = 0; i < v.size(); i++) {
v[i]++;
}
}
// 这样的写法如何?
void vector8_inc(std::vector<uint8_t>& v) {
for (size_t i = 0; i < const v.size(); i++) {
v[i]++;
}
}