Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // sploit.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <string.h>
- #include <stdlib.h>
- #include <Windows.h>
- #include <cmath>
- static double LibPow(double x, int n)
- {
- if (n < 0)
- { return (1.0 / LibPow(x, -n)); }
- switch (n)
- {
- case 0:
- { return (1.0); }
- case 1:
- { return (x); }
- case 2:
- { return (x * x); }
- case 3:
- { return (x * x * x); }
- case 4:
- {
- double x2 = x * x;
- return (x2 * x2);
- } case 5:
- {
- double x2 = x * x;
- return (x2 * x2 * x);
- }
- case 6:
- {
- double x2 = x * x;
- return (x2 * x2 * x2);
- }
- case 7:
- {
- double x3 = x * x * x;
- return (x3 * x3 * x);
- }
- case 8:
- {
- double x2 = x * x;
- double x4 = x2 * x2;
- return (x4 * x4);
- }
- case 9:
- {
- double x3 = x * x * x;
- return (x3 * x3 * x3);
- }
- case 10:
- {
- double x2 = x * x;
- double x4 = x2 * x2;
- return (x4 * x4 * x2);
- }
- default:
- { return std::pow(x, n); }
- }
- }
- static double LibIfPow(double x, int n)
- {
- if (n < 0)
- { return (1.0 / LibPow(x, -n)); }
- if(n == 0) return (1.0);
- else if(n == 1) return (x);
- else if(n == 2) return (x * x);
- else if(n == 3) return (x * x * x);
- else if(n == 4) {
- double x2 = x * x;
- return (x2 * x2);
- }
- else if(n == 5) {
- double x2 = x * x;
- return (x2 * x2 * x);
- } else if(n == 6) {
- double x2 = x * x;
- return (x2 * x2 * x2);
- } else if(n == 7) {
- double x3 = x * x * x;
- return (x3 * x3 * x);
- }
- else if(n == 8) {
- double x2 = x * x;
- double x4 = x2 * x2;
- return (x4 * x4);
- }
- else if(n == 9) {
- double x3 = x * x * x;
- return (x3 * x3 * x3);
- } else if(n == 10) {
- double x2 = x * x;
- double x4 = x2 * x2;
- return (x4 * x4 * x2);
- } else { return std::pow(x, n); }
- }
- #define METHOD 3
- #define LIMIT 11
- int _tmain(int argc, _TCHAR* argv[])
- {
- DWORD64 begin = __rdtsc();
- double sum = 0;
- for(int i = 0; i < 100000000; ++i)
- {
- #if METHOD == 1
- sum += LibPow(112.3, rand() % LIMIT);
- #else
- #if METHOD == 2
- sum += LibIfPow(112.3, rand() % LIMIT);
- #else
- sum += std::pow(112.3, rand() % LIMIT);
- #endif
- #endif
- }
- DWORD64 end = __rdtsc();
- DWORD64 diff = end-begin;
- LARGE_INTEGER res;
- QueryPerformanceFrequency(&res);
- printf("\n%llu %llu", diff, diff/res.QuadPart);
- return sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement