| 261 | } |
| 262 | |
| 263 | void Sample3Module::QueryStringTest(const AFGUID& guid, size_t count, const uint32_t index) |
| 264 | { |
| 265 | auto pEntity = m_pKernelModule->GetEntity(guid); |
| 266 | if (nullptr == pEntity) |
| 267 | { |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | std::cout << "----------[" << index << "] time [query string] test start----------" << std::endl; |
| 272 | |
| 273 | // query string data with int key |
| 274 | auto begin = std::chrono::system_clock::now().time_since_epoch(); |
| 275 | for (size_t i = 0; i < count; i++) |
| 276 | { |
| 277 | auto& value = pEntity->GetString(AFEntityMetaPlayer::name_index()); |
| 278 | } |
| 279 | auto end = std::chrono::system_clock::now().time_since_epoch(); |
| 280 | auto time_int_key = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count(); |
| 281 | |
| 282 | // query string data with string key |
| 283 | begin = std::chrono::system_clock::now().time_since_epoch(); |
| 284 | for (size_t i = 0; i < count; i++) |
| 285 | { |
| 286 | auto& value = pEntity->GetString(AFEntityMetaPlayer::name()); |
| 287 | } |
| 288 | end = std::chrono::system_clock::now().time_since_epoch(); |
| 289 | auto time_string_key = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count(); |
| 290 | |
| 291 | std::cout << "[" << count << "] query with [int key] time = " << time_int_key << " ms" |
| 292 | << " with [string key] time = " << time_string_key << std::endl; |
| 293 | |
| 294 | // query string data with int key |
| 295 | begin = std::chrono::system_clock::now().time_since_epoch(); |
| 296 | for (size_t i = 0; i < count; i++) |
| 297 | { |
| 298 | auto pObj = m_pKernelModule->GetEntity(guid); |
| 299 | if (nullptr == pObj) |
| 300 | { |
| 301 | return; |
| 302 | } |
| 303 | |
| 304 | auto& value = pObj->GetString(AFEntityMetaPlayer::name_index()); |
| 305 | } |
| 306 | end = std::chrono::system_clock::now().time_since_epoch(); |
| 307 | time_int_key = std::chrono::duration_cast<std::chrono::milliseconds>(end - begin).count(); |
| 308 | |
| 309 | // query string data with string key |
| 310 | begin = std::chrono::system_clock::now().time_since_epoch(); |
| 311 | for (size_t i = 0; i < count; i++) |
| 312 | { |
| 313 | auto pObj = m_pKernelModule->GetEntity(guid); |
| 314 | if (nullptr == pObj) |
| 315 | { |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | auto& value = pObj->GetString(AFEntityMetaPlayer::name()); |
| 320 | } |