Created
September 18, 2021 10:47
-
-
Save marcelhollerbach/2c366b223075baf6be6d955fdfeedb6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <immintrin.h> | |
#include <vector> | |
#include <inttypes.h> | |
#include <chrono> | |
#include <iostream> | |
using namespace std; | |
void run_million_adds() { | |
vector<uint64_t> test1(1000000); | |
for (int i = 2; i < 1000000; ++i){ | |
test1[i + 1] = test1[i - 1] + test1[i]; | |
} | |
} | |
void run_million_pext() { | |
vector<uint64_t> test1(1000000); | |
for (int i = 2; i < 1000000; ++i){ | |
test1[i + 1] = _pext_u64(test1[i - 1], test1[i]) + i; | |
} | |
} | |
int main(int argc, char const *argv[]) | |
{ | |
for (int i = 0; i < 1000; ++i) | |
{ | |
auto start = std::chrono::high_resolution_clock::now(); | |
run_million_adds(); | |
auto end_add = std::chrono::high_resolution_clock::now(); | |
run_million_pext(); | |
auto end_pext = std::chrono::high_resolution_clock::now(); | |
cout << "ADD: " << ((std::chrono::duration<double>)(end_add - start)).count() << endl; | |
cout << "PEXT: " << ((std::chrono::duration<double>)(end_pext - end_add)).count() << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment