Created
March 4, 2022 13:03
-
-
Save randombit/adaaaecfc23906af0fe8f3e7ea0257cd to your computer and use it in GitHub Desktop.
Benchmark of libargon2
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
#include <argon2.h> | |
#include <stdint.h> | |
#include <time.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
uint64_t timestamp() | |
{ | |
struct timespec ts; | |
if(::clock_gettime(CLOCK_MONOTONIC_RAW, &ts) == 0) | |
{ | |
return (static_cast<uint64_t>(ts.tv_sec) * 1000000000) + static_cast<uint64_t>(ts.tv_nsec); | |
} | |
abort(); | |
} | |
int main() | |
{ | |
const size_t t = 128; | |
const size_t m = 65536; | |
const size_t p = 8; | |
uint8_t hash[32]; | |
const uint8_t pwd[4] = { 1, 2, 3, 4 }; | |
const uint8_t salt[8] = { 1, 2, 3, 4, 5, 6, 7, 8 }; | |
const uint64_t start = timestamp(); | |
const size_t runtime = 3000; | |
const size_t NS_TO_MS = 1000000; | |
size_t runs = 0; | |
for(;;) | |
{ | |
runs += 1; | |
argon2id_hash_raw(t, m, p, | |
pwd, sizeof(pwd), | |
salt, sizeof(salt), | |
hash, sizeof(hash)); | |
const uint64_t dur = timestamp() - start; | |
if(dur > runtime*NS_TO_MS) | |
{ | |
break; | |
} | |
} | |
const uint64_t dur = timestamp() - start; | |
double ms_per_run = (static_cast<double>(dur) / runs) / NS_TO_MS; | |
printf("%d runs in %f ms -> %f ms/run", | |
runs, static_cast<double>(dur)/NS_TO_MS, ms_per_run); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment