Skip to content

Commit

Permalink
Fix some GCC workflow runner bug
Browse files Browse the repository at this point in the history
  • Loading branch information
alainesp committed Feb 3, 2024
1 parent 02bd451 commit f065c20
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
7 changes: 3 additions & 4 deletions example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <wy.hpp>
#include <random>

void main_rand()
static void main_rand()
{
// Create a pseudo-random generator
wy::rand r;
Expand All @@ -34,15 +34,14 @@ void main_rand()

#include <unordered_map>
#include <iostream>
#include <format>

struct Person
{
std::string name;
std::string surname;
};

void main_hash()
static void main_hash()
{
// Create random persons
std::vector<Person> persons;
Expand All @@ -61,7 +60,7 @@ void main_hash()
for (size_t i = 0; i < persons.size() * 2; i++)
persons_found += h.count(std::string("Person Name") + std::to_string(i));

std::cout << std::format("Found {} persons", persons_found) << std::endl;
std::cout << "Found " << persons_found << " persons" << std::endl;
}

int main()
Expand Down
35 changes: 17 additions & 18 deletions performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
#include <wy.hpp>
#include <chrono>
#include <iostream>
#include <format>

void main_rand()
static void main_rand()
{
constexpr size_t numIter = 1'000'000'000;
constexpr size_t numIterStream = 10'000'000;
Expand All @@ -31,7 +30,7 @@ void main_rand()
for (size_t i = 0; i < numIter; i++) no_op ^= r();// Generate a random number
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << std::format("Random : {}M op/sec\n", numIter / duration.count());// Show performance on millions operations per second
std::cout << "Random : " << numIter / duration.count() << "M op/sec\n";// Show performance on millions operations per second

std::cout << "--------------------------------------------------" << std::endl;
//////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -41,7 +40,7 @@ void main_rand()
for (size_t i = 0; i < numIter; i++) no_opd += r.uniform_dist();// Generate a random number
stop = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << std::format("Uniform [0, 1) : {}M op/sec\n", numIter / duration.count());// Show performance on millions operations per second
std::cout << "Uniform [0, 1) : " << numIter / duration.count() << "M op/sec\n";// Show performance on millions operations per second

//////////////////////////////////////////////////////////////////////////////////////
// Uniform operation
Expand All @@ -50,7 +49,7 @@ void main_rand()
for (size_t i = 0; i < numIter; i++) no_opd += r.uniform_dist(5.6, 11.7);// Generate a random number
stop = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << std::format("Uniform [min, max) : {}M op/sec\n", numIter / duration.count());// Show performance on millions operations per second
std::cout << "Uniform [min, max) : " << numIter / duration.count() << "M op/sec\n";// Show performance on millions operations per second

#if !WYHASH_32BIT_MUM
//////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -60,7 +59,7 @@ void main_rand()
for (size_t i = 0; i < numIter; i++) no_op ^= r.uniform_dist(5000);// Generate a random number
stop = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << std::format("Uniform [0, k) : {}M op/sec\n", numIter / duration.count());// Show performance on millions operations per second
std::cout << "Uniform [0, k) : " << numIter / duration.count() << "M op/sec\n";// Show performance on millions operations per second

std::cout << "--------------------------------------------------" << std::endl;
#endif
Expand All @@ -72,7 +71,7 @@ void main_rand()
for (size_t i = 0; i < numIter; i++) no_opd += r.gaussian_dist();// Generate a random number
stop = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << std::format("Gaussian [0, 1] : {}M op/sec\n", numIter / duration.count());// Show performance on millions operations per second
std::cout << "Gaussian [0, 1] : " << numIter / duration.count() << "M op/sec\n";// Show performance on millions operations per second

//////////////////////////////////////////////////////////////////////////////////////
// Gaussian operation
Expand All @@ -81,7 +80,7 @@ void main_rand()
for (size_t i = 0; i < numIter; i++) no_opd += r.gaussian_dist(1.2, 2.5);// Generate a random number
stop = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << std::format("Gaussian [mean, std]: {}M op/sec\n", numIter / duration.count());// Show performance on millions operations per second
std::cout << "Gaussian [mean, std]: " << numIter / duration.count() << "M op/sec\n";// Show performance on millions operations per second

std::cout << "--------------------------------------------------" << std::endl;

Expand All @@ -98,7 +97,7 @@ void main_rand()
}
stop = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << std::format("Stream [1024] : {:.1f} GB/sec\n", GiB2GB * numIterStream / duration.count());// Show performance on GB per second
std::cout << "Stream [1024] : " << GiB2GB * numIterStream / duration.count() << " GB/sec\n";// Show performance on GB per second

//////////////////////////////////////////////////////////////////////////////////////
// Stream operation
Expand All @@ -111,15 +110,15 @@ void main_rand()
}
stop = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << std::format("Stream [4096] : {:.1f} GB/sec\n", GiB2GB * numIterStream * 4 / duration.count());// Show performance on GB per second
std::cout << "Stream [4096] : " << GiB2GB * numIterStream * 4 / duration.count() << " GB/sec\n";// Show performance on GB per second

std::cout << "--------------------------------------------------" << std::endl;

// Ensures no optimization
std::cout << std::format("{}", (no_op + no_opd) ? "" : "Bad luck!");
std::cout << ((no_op + no_opd) ? "" : "Bad luck!") << std::endl;
}

void main_hash()
static void main_hash()
{
constexpr size_t numIter = 100'000'000;
uint64_t no_op = 0;// variable to restrict compiler optimizations
Expand All @@ -136,7 +135,7 @@ void main_hash()
for (size_t i = 0; i < numIter; i++) no_op ^= hasherUint64(i);// Hash
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << std::format("uint64_t : {:4}M op/sec\n", numIter / duration.count());// Show performance on millions operations per second
std::cout << "uint64_t : " << numIter / duration.count() << "M op/sec\n";// Show performance on millions operations per second

//////////////////////////////////////////////////////////////////////////////////////
// String operation
Expand All @@ -147,33 +146,33 @@ void main_hash()
for (size_t i = 0; i < numIter; i++) no_op ^= hasherStr(small);// Hash
stop = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << std::format("std::string(14) : {:4}M op/sec\n", numIter / duration.count());// Show performance on millions operations per second
std::cout << "std::string(14) : " << numIter / duration.count() << "M op/sec\n";// Show performance on millions operations per second

small += "01234567890123";
start = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i < numIter; i++) no_op ^= hasherStr(small);// Hash
stop = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << std::format("std::string(28) : {:4}M op/sec\n", numIter / duration.count());// Show performance on millions operations per second
std::cout << "std::string(28) : " << numIter / duration.count() << "M op/sec\n";// Show performance on millions operations per second

small += small; small += small;
start = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i < numIter; i++) no_op ^= hasherStr(small);// Hash
stop = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << std::format("std::string(112) : {:4}M op/sec\n", numIter / duration.count());// Show performance on millions operations per second
std::cout << "std::string(112) : " << numIter / duration.count() << "M op/sec\n";// Show performance on millions operations per second

small += small; small += small;
start = std::chrono::high_resolution_clock::now();
for (size_t i = 0; i < numIter; i++) no_op ^= hasherStr(small);// Hash
stop = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
std::cout << std::format("std::string(448) : {:4}M op/sec\n", numIter / duration.count());// Show performance on millions operations per second
std::cout << "std::string(448) : " << numIter / duration.count() << "M op/sec\n";// Show performance on millions operations per second

std::cout << "--------------------------------------------------" << std::endl;

// Ensures no optimization
std::cout << std::format("{}", no_op ? "" : "Bad luck!");
std::cout << (no_op ? "" : "Bad luck!") << std::endl;
}

int main()
Expand Down

0 comments on commit f065c20

Please sign in to comment.