-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more benchmarks.
- Loading branch information
Showing
4 changed files
with
417 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// SPDX-FileCopyrightText: © 2024 Melg Eight <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include <blowfish_cipher.h> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-FileCopyrightText: © 2024 Melg Eight <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
#ifndef BLOWFISH_CIPHER_H | ||
#define BLOWFISH_CIPHER_H | ||
|
||
#include <openssl/blowfish.h> | ||
|
||
namespace swarm {} // namespace swarm | ||
|
||
#endif // BLOWFISH_CIPHER_H |
84 changes: 84 additions & 0 deletions
84
sources/swarm/tests/benchmark_tests/sources/crypt/bench.cc
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include <random> | ||
#include <unordered_set> | ||
|
||
[[nodiscard]] inline std::vector<int> RandN(int n) noexcept { | ||
if (n <= 0) { | ||
return std::vector<int>{}; | ||
} | ||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::uniform_int_distribution<int> distribution; | ||
std::vector<int> result; | ||
result.reserve(n); | ||
for (int i = 0; i < n; ++i) { | ||
result.push_back(distribution(gen)); | ||
} | ||
return result; | ||
} | ||
|
||
static void RandNBench(benchmark::State& state) { | ||
// Code inside this loop is measured repeatedly | ||
for (auto _ : state) { | ||
const auto result = RandN(10'000); | ||
if (result.size() != 10'000) { | ||
abort(); | ||
} | ||
benchmark::DoNotOptimize(result); | ||
} | ||
} | ||
// Register the function as a benchmark | ||
BENCHMARK(RandNBench); | ||
|
||
[[nodiscard]] inline std::vector<int> RandN1(int n) noexcept { | ||
if (n <= 0) { | ||
return std::vector<int>{}; | ||
} | ||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::uniform_int_distribution<int> distribution; | ||
std::vector<int> result(n, 0); | ||
for (int i = 0; i < n; ++i) { | ||
result[i] = distribution(gen); | ||
} | ||
return result; | ||
} | ||
|
||
static void RandN1Bench(benchmark::State& state) { | ||
// Code inside this loop is measured repeatedly | ||
for (auto _ : state) { | ||
const auto result = RandN1(10'000); | ||
if (result.size() != 10'000) { | ||
abort(); | ||
} | ||
benchmark::DoNotOptimize(result); | ||
} | ||
} | ||
// Register the function as a benchmark | ||
BENCHMARK(RandN1Bench); | ||
|
||
[[nodiscard]] inline std::vector<int> UniqRandN1(int n) noexcept { | ||
if (n <= 0) { | ||
return std::vector<int>{}; | ||
} | ||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::uniform_int_distribution<int> distribution; | ||
std::unordered_set<int> unique; | ||
while (unique.size() < n) { | ||
unique.insert(distribution(gen)); | ||
} | ||
return std::vector<int>{unique.begin(), unique.end()}; | ||
} | ||
|
||
static void UniqRandN1Bench(benchmark::State& state) { | ||
// Code inside this loop is measured repeatedly | ||
for (auto _ : state) { | ||
const auto result = UniqRandN1(10'000); | ||
if (result.size() != 10'000) { | ||
abort(); | ||
} | ||
benchmark::DoNotOptimize(result); | ||
} | ||
} | ||
// Register the function as a benchmark | ||
BENCHMARK(UniqRandN1Bench); |
Oops, something went wrong.