4 ms·
To follow up: I did do a quick modification of the test harness using a gigantic mbox file I had and some really crappy MIME parsing code. $ ./email input size:
by jcranmer 11y ago
To follow up: I did do a quick modification of the test harness using a gigantic mbox file I had and some really crappy MIME parsing code.
$ ./email
input size: 86023056 (that's only base64-encoded text, this is a ~562MB file).
improved scalar... 1.528
scalar... 1.564 (speed up: 0.98)
SSE... 1.533 (speed up: 1.00)
Null... 1.447 (speed up: 1.06)
So about 5% of the test was spent doing base64 decoding, and the improved scalar had a 48% over regular scalar and SSE had a speedup of 40% over regular scalar on just the base64 section. So the short conclusion is that SSE doesn't really get any speedup on short strings.
The additional test code, for full disclosure (yes, it's not correct, but this is easier to code and get some numbers rather than nothing. A more correct solution would really hurt the SSE bit more than other ones.):
template <typename T>
void run_email(T callback) {
static std::string cte{"content-transfer-encoding"};
std::ifstream mbox("/tmp/test.mbox");
std::string line;
bool inHeader = true;
bool base64Body = false;
while (std::getline(mbox, line)) {
if (line[line.length() - 1] == '\r')
line.pop_back();
if (inHeader) {
std::transform(line.begin(), line.end(), line.begin(), ::tolower);
if (line.find(cte) == 0 && line.find("base64") != std::string::npos)
base64Body = true;
if (line.empty())
inHeader = false;
} else {
if (line.substr(0, 5) == "From " || line.substr(0, 2) == "--") {
inHeader = true;
base64Body = false;
continue;
}
if (base64Body) {
while (line[line.size() - 1] == '=')
line.pop_back();
while (line.size() % 16 != 0)
line.push_back('A');
uint8_t *text = (uint8_t*)&line[0];
callback(text, line.size(), text);
}
}
}
}