| 328 | } |
| 329 | |
| 330 | void Sample3Module::QueryIntTest(const AFGUID& guid, size_t count, const uint32_t index) |
| 331 | { |
| 332 | auto pEntity = m_pKernelModule->GetEntity(guid); |
| 333 | if (nullptr == pEntity) |
| 334 | { |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | std::cout << "----------[" << index << "] time [query int] test start----------" << std::endl; |
| 339 | |
| 340 | // query string data with int key |
| 341 | auto begin = std::chrono::system_clock::now().time_since_epoch(); |
| 342 | for (size_t i = 0; i < count; i++) |
| 343 | { |
| 344 | auto value = pEntity->GetInt32(AFEntityMetaPlayer::gender_index()); |
| 345 | } |
| 346 | auto end = std::chrono::system_clock::now().time_since_epoch(); |
| 347 | auto time_int_key = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count(); |
| 348 | |
| 349 | // query string data with string key |
| 350 | begin = std::chrono::system_clock::now().time_since_epoch(); |
| 351 | for (size_t i = 0; i < count; i++) |
| 352 | { |
| 353 | auto value = pEntity->GetInt32(AFEntityMetaPlayer::gender()); |
| 354 | } |
| 355 | end = std::chrono::system_clock::now().time_since_epoch(); |
| 356 | auto time_string_key = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count(); |
| 357 | |
| 358 | std::cout << "[" << count << "] query with [int key] time = " << time_int_key << " ms" |
| 359 | << " with [string key] time = " << time_string_key << std::endl; |
| 360 | |
| 361 | // query string data with int key |
| 362 | begin = std::chrono::system_clock::now().time_since_epoch(); |
| 363 | for (size_t i = 0; i < count; i++) |
| 364 | { |
| 365 | auto pObj = m_pKernelModule->GetEntity(guid); |
| 366 | if (nullptr == pObj) |
| 367 | { |
| 368 | return; |
| 369 | } |
| 370 | |
| 371 | auto value = pObj->GetInt32(AFEntityMetaPlayer::gender_index()); |
| 372 | } |
| 373 | end = std::chrono::system_clock::now().time_since_epoch(); |
| 374 | time_int_key = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count(); |
| 375 | |
| 376 | // query string data with string key |
| 377 | begin = std::chrono::system_clock::now().time_since_epoch(); |
| 378 | for (size_t i = 0; i < count; i++) |
| 379 | { |
| 380 | auto pObj = m_pKernelModule->GetEntity(guid); |
| 381 | if (nullptr == pObj) |
| 382 | { |
| 383 | return; |
| 384 | } |
| 385 | |
| 386 | auto value = pObj->GetInt32(AFEntityMetaPlayer::gender()); |
| 387 | } |