-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced JPerfUtils with JBenchUtils (class format), set event number…
… and caller name based seed inside constructor (Fixes #315)
- Loading branch information
1 parent
c5674aa
commit 67719cc
Showing
14 changed files
with
178 additions
and
35 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
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
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
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
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
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
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,91 @@ | ||
|
||
// Copyright 2020, Jefferson Science Associates, LLC. | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
|
||
#include "JBenchUtils.h" | ||
|
||
|
||
JBenchUtils::JBenchUtils(size_t event_number, std::string caller_name) | ||
{ | ||
std::hash<std::string> hasher; | ||
long seed = event_number ^ hasher(caller_name); | ||
m_generator = std::mt19937(seed); | ||
} | ||
|
||
|
||
size_t JBenchUtils::rand_size(size_t avg, double spread) { | ||
auto delta = static_cast<size_t>(avg*spread); | ||
std::uniform_int_distribution<size_t> distribution(avg-delta, avg+delta); | ||
return distribution(m_generator); | ||
} | ||
|
||
|
||
int JBenchUtils::randint(int min, int max) { | ||
std::uniform_int_distribution<int> distribution(min, max); | ||
return distribution(m_generator); | ||
} | ||
|
||
double JBenchUtils::randdouble(double min, double max) { | ||
std::uniform_real_distribution<double> dist(min, max); | ||
return dist(m_generator); | ||
} | ||
|
||
float JBenchUtils::randfloat(float min, float max) { | ||
std::uniform_real_distribution<float> dist(min, max); | ||
return dist(m_generator); | ||
} | ||
|
||
uint64_t JBenchUtils::consume_cpu_ms(uint64_t millisecs, double spread, bool fix_flops) { | ||
|
||
uint64_t sampled = rand_size(millisecs, spread); | ||
uint64_t result = 0; | ||
|
||
if (fix_flops) { | ||
// Perform a fixed amount of work in a variable time | ||
const uint64_t appx_iters_per_millisec = 14000; | ||
sampled *= appx_iters_per_millisec; | ||
|
||
for (uint64_t i=0; i<sampled; ++i) { | ||
double a = (m_generator)(); | ||
double b = sqrt(a * pow(1.23, -a)) / a; | ||
result += long(b); | ||
} | ||
} | ||
else { | ||
// Perform a variable amount of work in a fixed time | ||
auto duration = std::chrono::milliseconds(sampled); | ||
auto start_time = std::chrono::steady_clock::now(); | ||
while ((std::chrono::steady_clock::now() - start_time) < duration) { | ||
|
||
double a = (m_generator)(); | ||
double b = sqrt(a * pow(1.23, -a)) / a; | ||
result += long(b); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
uint64_t JBenchUtils::read_memory(const std::vector<char>& buffer) { | ||
|
||
auto length = buffer.size(); | ||
uint64_t sum = 0; | ||
for (unsigned i=0; i<length; ++i) { | ||
sum += buffer[i]; | ||
} | ||
return sum; | ||
} | ||
|
||
uint64_t JBenchUtils::write_memory(std::vector<char>& buffer, uint64_t bytes, double spread) { | ||
|
||
uint64_t sampled = rand_size(bytes, spread); | ||
for (unsigned i=0; i<sampled; ++i) { | ||
buffer.push_back(2); | ||
} | ||
return sampled*2; | ||
} | ||
|
||
|
||
|
||
|
||
|
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,33 @@ | ||
|
||
// Copyright 2020, Jefferson Science Associates, LLC. | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
#pragma once | ||
|
||
#include <vector> | ||
#include <random> | ||
#include <string> | ||
#include <algorithm> | ||
#include <string> | ||
#include <typeinfo> | ||
#include <chrono> | ||
|
||
|
||
class JBenchUtils { | ||
|
||
std::mt19937 m_generator; | ||
|
||
public: | ||
|
||
JBenchUtils(size_t event_number, std::string caller_name); | ||
|
||
size_t rand_size(size_t avg, double spread); | ||
int randint(int min, int max); | ||
double randdouble(double min=0.0, double max=1000.0); | ||
float randfloat(float min=0.0, float max=1000.0); | ||
|
||
uint64_t consume_cpu_ms(uint64_t millisecs, double spread=0.0, bool fix_flops=true); | ||
uint64_t read_memory(const std::vector<char>& buffer); | ||
uint64_t write_memory(std::vector<char>& buffer, uint64_t bytes, double spread=0.0); | ||
|
||
}; |
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
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
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
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
Oops, something went wrong.