-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simplified measurement loop for password hashes
- Loading branch information
Showing
7 changed files
with
62 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ rotate.h | |
rounding.h | ||
scan_name.h | ||
stl_util.h | ||
time_utils.h | ||
</header:internal> | ||
|
||
<requires> | ||
|
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,42 @@ | ||
/** | ||
* (C) 2024 Jack Lloyd | ||
* | ||
* Botan is released under the Simplified BSD License (see license.txt) | ||
*/ | ||
|
||
#ifndef BOTAN_TIME_UTILS_H_ | ||
#define BOTAN_TIME_UTILS_H_ | ||
|
||
#include <botan/internal/os_utils.h> | ||
#include <chrono> | ||
|
||
namespace Botan { | ||
|
||
template <typename F> | ||
uint64_t measure_cost(std::chrono::milliseconds trial_msec, F func) { | ||
const uint64_t trial_nsec = std::chrono::duration_cast<std::chrono::nanoseconds>(trial_msec).count(); | ||
|
||
uint64_t total_nsec = 0; | ||
uint64_t trials = 0; | ||
|
||
auto trial_start = OS::get_system_timestamp_ns(); | ||
|
||
for(;;) { | ||
const auto start = OS::get_system_timestamp_ns(); | ||
func(); | ||
const auto end = OS::get_system_timestamp_ns(); | ||
|
||
if(end >= start) { | ||
total_nsec += (end - start); | ||
trials += 1; | ||
|
||
if((end - trial_start) >= trial_nsec) { | ||
return (total_nsec / trials); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} // namespace Botan | ||
|
||
#endif |