Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. // comparemapternary.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <conio.h>
  6. #include <cstdint>
  7. #include <functional>
  8. #include <map>
  9.  
  10. #include <iostream>
  11. #include <chrono>
  12.  
  13. template<typename TimeT = std::chrono::milliseconds>
  14. struct measure
  15. {
  16.     template<typename F, typename ...Args>
  17.     static typename TimeT::rep execution(F&& func, Args&&... args)
  18.     {
  19.         auto start = std::chrono::steady_clock::now();
  20.         std::forward<decltype(func)>(func)(std::forward<Args>(args)...);
  21.         auto duration = std::chrono::duration_cast< TimeT>
  22.             (std::chrono::steady_clock::now() - start);
  23.         return duration.count();
  24.     }
  25. };
  26.  
  27. int getGameVersion() {
  28.     return 36;
  29. }
  30.  
  31. uint64_t getHandlingOffset_chain() {
  32.     int gameVersion = getGameVersion();
  33.     auto offset = gameVersion >= 24 ? 0x830 : 0;
  34.     offset = gameVersion >= 26 ? 0x850 : offset;
  35.     offset = gameVersion >= 28 ? 0x878 : offset;
  36.     offset = gameVersion >= 34 ? 0x888 : offset;
  37.     offset = gameVersion >= 36 ? 0x8A8 : offset;
  38.     return offset;
  39. }
  40.  
  41. uint64_t getHandlingOffset_map() {
  42.     static const std::map<int, uint64_t, std::greater<int>> kVersionOffsets{
  43.         { 0, 0 },
  44.         { 24, 0x830 },
  45.         { 26, 0x850 },
  46.         { 28, 0x878 },
  47.         { 34, 0x888 },
  48.         { 36, 0x8A8 }
  49.     };
  50.  
  51.     const int gameVersion = getGameVersion();
  52.     return kVersionOffsets.lower_bound(gameVersion)->second;
  53. }
  54.  
  55. void run_chain(int times) {
  56.     for (int i = 0 ; i < times; i++) {
  57.         getHandlingOffset_chain();
  58.     }
  59. }
  60.  
  61. void run_map(int times) {
  62.     for (int i = 0; i < times; i++) {
  63.         getHandlingOffset_map();
  64.     }
  65. }
  66.  
  67. int main() {
  68.     std::cout << "press something to start" << std::endl;
  69.     _getch();
  70.  
  71.     std::cout << "chain: " << measure<>::execution(run_chain, 1000000) << std::endl;
  72.     std::cout << "map:   " << measure<>::execution(run_map,   1000000) << std::endl;
  73.     _getch();
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement