chore: add a benchmark comparing lpStringToInt64 to SimpleAtoi (#3815)

Seems that lpStringToInt64 is fairly optimized.
On c7g:

```
BM_LpString2Int/1      27383 ns        27381 ns       204149
BM_LpString2Int/2      24535 ns        24534 ns       227981
```

so SimpleAtoi has only ~10% improvement.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2024-09-29 09:04:25 +03:00 committed by GitHub
parent a3cabd10d3
commit 73002dc048
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -761,7 +761,7 @@ static void BM_UnpackSimd(benchmark::State& state) {
BENCHMARK(BM_UnpackSimd); BENCHMARK(BM_UnpackSimd);
static void BM_LpCompare(benchmark::State& state) { static void BM_LpCompare(benchmark::State& state) {
std::random_device rd; std::mt19937_64 rd;
uint8_t* lp = lpNew(0); uint8_t* lp = lpNew(0);
for (unsigned i = 0; i < 100; ++i) { for (unsigned i = 0; i < 100; ++i) {
lp = lpAppendInteger(lp, rd() % (1ULL << 48)); lp = lpAppendInteger(lp, rd() % (1ULL << 48));
@ -780,7 +780,7 @@ static void BM_LpCompare(benchmark::State& state) {
BENCHMARK(BM_LpCompare); BENCHMARK(BM_LpCompare);
static void BM_LpCompareInt(benchmark::State& state) { static void BM_LpCompareInt(benchmark::State& state) {
std::random_device rd; std::mt19937_64 rd;
uint8_t* lp = lpNew(0); uint8_t* lp = lpNew(0);
for (unsigned i = 0; i < 100; ++i) { for (unsigned i = 0; i < 100; ++i) {
lp = lpAppendInteger(lp, rd() % (1ULL << 48)); lp = lpAppendInteger(lp, rd() % (1ULL << 48));
@ -832,4 +832,26 @@ static void BM_LpGet(benchmark::State& state) {
} }
BENCHMARK(BM_LpGet)->Arg(1)->Arg(2); BENCHMARK(BM_LpGet)->Arg(1)->Arg(2);
extern "C" int lpStringToInt64(const char* s, unsigned long slen, int64_t* value);
static void BM_LpString2Int(benchmark::State& state) {
int version = state.range(0);
std::mt19937_64 rd;
vector<string> values;
for (unsigned i = 0; i < 1000; ++i) {
int64_t val = rd();
values.push_back(absl::StrCat(val));
}
int64_t ival = 0;
while (state.KeepRunning()) {
for (const auto& val : values) {
int res = version == 1 ? lpStringToInt64(val.data(), val.size(), &ival)
: absl::SimpleAtoi(val, &ival);
benchmark::DoNotOptimize(res);
}
}
}
BENCHMARK(BM_LpString2Int)->Arg(1)->Arg(2);
} // namespace dfly } // namespace dfly