Skip to content

Commit

Permalink
Allocate 16k scratch on heap (#1991)
Browse files Browse the repository at this point in the history
### Issues:
Addresses: P169365635

### Description of changes: 
* Allocate large value on the heap instead of stack.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.
  • Loading branch information
justsmth authored Nov 13, 2024
1 parent 096f73a commit f9757c4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tool/speed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1257,17 +1257,19 @@ static bool SpeedHmacOneShot(const EVP_MD *md, const std::string &name,
return true;
}

const size_t SCRATCH_SIZE = 16384;

using RandomFunction = std::function<void(uint8_t *, size_t)>;
static bool SpeedRandomChunk(RandomFunction function, std::string name, size_t chunk_len) {
uint8_t scratch[16384];
std::unique_ptr<uint8_t[]> scratch(new uint8_t[SCRATCH_SIZE]);

if (chunk_len > sizeof(scratch)) {
if (chunk_len > SCRATCH_SIZE) {
return false;
}

TimeResults results;
if (!TimeFunction(&results, [chunk_len, &scratch, &function]() -> bool {
function(scratch, chunk_len);
function(scratch.get(), chunk_len);
return true;
})) {
return false;
Expand Down

0 comments on commit f9757c4

Please sign in to comment.