Skip to content

Instantly share code, notes, and snippets.

@marcelhollerbach
Created September 18, 2021 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcelhollerbach/2c366b223075baf6be6d955fdfeedb6e to your computer and use it in GitHub Desktop.
Save marcelhollerbach/2c366b223075baf6be6d955fdfeedb6e to your computer and use it in GitHub Desktop.
#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