mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
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:
parent
a3cabd10d3
commit
73002dc048
1 changed files with 24 additions and 2 deletions
|
@ -761,7 +761,7 @@ static void BM_UnpackSimd(benchmark::State& state) {
|
|||
BENCHMARK(BM_UnpackSimd);
|
||||
|
||||
static void BM_LpCompare(benchmark::State& state) {
|
||||
std::random_device rd;
|
||||
std::mt19937_64 rd;
|
||||
uint8_t* lp = lpNew(0);
|
||||
for (unsigned i = 0; i < 100; ++i) {
|
||||
lp = lpAppendInteger(lp, rd() % (1ULL << 48));
|
||||
|
@ -780,7 +780,7 @@ static void BM_LpCompare(benchmark::State& state) {
|
|||
BENCHMARK(BM_LpCompare);
|
||||
|
||||
static void BM_LpCompareInt(benchmark::State& state) {
|
||||
std::random_device rd;
|
||||
std::mt19937_64 rd;
|
||||
uint8_t* lp = lpNew(0);
|
||||
for (unsigned i = 0; i < 100; ++i) {
|
||||
lp = lpAppendInteger(lp, rd() % (1ULL << 48));
|
||||
|
@ -832,4 +832,26 @@ static void BM_LpGet(benchmark::State& state) {
|
|||
}
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue