Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // comparemapternary.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <conio.h>
- #include <cstdint>
- #include <functional>
- #include <map>
- #include <iostream>
- #include <chrono>
- template<typename TimeT = std::chrono::milliseconds>
- struct measure
- {
- template<typename F, typename ...Args>
- static typename TimeT::rep execution(F&& func, Args&&... args)
- {
- auto start = std::chrono::steady_clock::now();
- std::forward<decltype(func)>(func)(std::forward<Args>(args)...);
- auto duration = std::chrono::duration_cast< TimeT>
- (std::chrono::steady_clock::now() - start);
- return duration.count();
- }
- };
- int getGameVersion() {
- return 36;
- }
- uint64_t getHandlingOffset_chain() {
- int gameVersion = getGameVersion();
- auto offset = gameVersion >= 24 ? 0x830 : 0;
- offset = gameVersion >= 26 ? 0x850 : offset;
- offset = gameVersion >= 28 ? 0x878 : offset;
- offset = gameVersion >= 34 ? 0x888 : offset;
- offset = gameVersion >= 36 ? 0x8A8 : offset;
- return offset;
- }
- uint64_t getHandlingOffset_map() {
- static const std::map<int, uint64_t, std::greater<int>> kVersionOffsets{
- { 0, 0 },
- { 24, 0x830 },
- { 26, 0x850 },
- { 28, 0x878 },
- { 34, 0x888 },
- { 36, 0x8A8 }
- };
- const int gameVersion = getGameVersion();
- return kVersionOffsets.lower_bound(gameVersion)->second;
- }
- void run_chain(int times) {
- for (int i = 0 ; i < times; i++) {
- getHandlingOffset_chain();
- }
- }
- void run_map(int times) {
- for (int i = 0; i < times; i++) {
- getHandlingOffset_map();
- }
- }
- int main() {
- std::cout << "press something to start" << std::endl;
- _getch();
- std::cout << "chain: " << measure<>::execution(run_chain, 1000000) << std::endl;
- std::cout << "map: " << measure<>::execution(run_map, 1000000) << std::endl;
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement