Some checks failed
C/C++ CI / build-alpine-static (map[arch:riscv64 branch:latest-stable flags:-ffunction-sections]) (push) Has been cancelled
C/C++ CI / build-alpine-static (map[arch:x86_64 branch:latest-stable flags:-ffunction-sections]) (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-10 cpp:g++-10 flags: os:ubuntu-22.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-11 cpp:g++-11 flags: os:ubuntu-22.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-12 cpp:g++-12 flags: os:ubuntu-22.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-13 cpp:g++-13 flags: os:ubuntu-24.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-14 cpp:g++-14 flags: os:ubuntu-24.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-9 cpp:g++-9 flags: os:ubuntu-22.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu-static-libs (map[flags:-fuse-linker-plugin -ffunction-sections]) (push) Has been cancelled
C/C++ CI / build-ubuntu-aarch64 (map[flags:-fuse-linker-plugin -ffunction-sections -mfix-cortex-a53-835769 -mfix-cortex-a53-843419 os:ubuntu-22.04-arm]) (push) Has been cancelled
C/C++ CI / build-ubuntu-riscv64 (map[flags:-fuse-linker-plugin -ffunction-sections os:ubuntu-22.04]) (push) Has been cancelled
C/C++ CI / build-windows-msys2 (map[c:clang cxx:clang++ flags:-fuse-ld=lld -Wno-unused-command-line-argument -Wno-nan-infinity-disabled -Wno-attributes]) (push) Has been cancelled
C/C++ CI / build-windows-msys2 (map[c:gcc cxx:g++ flags:-ffunction-sections -Wno-error=maybe-uninitialized -Wno-error=attributes -Wno-attributes]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2022 rx:OFF tls:OFF upnp:OFF vs:Visual Studio 17 2022 vspath:C:\Program Files\Microsoft Visual Studio\2022\Enterprise]) (push) Has been cancelled
C/C++ CI / build-alpine-static (map[arch:aarch64 branch:latest-stable flags:-ffunction-sections -mfix-cortex-a53-835769 -mfix-cortex-a53-843419]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2022 rx:OFF tls:ON upnp:OFF vs:Visual Studio 17 2022 vspath:C:\Program Files\Microsoft Visual Studio\2022\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2022 rx:OFF tls:ON upnp:ON vs:Visual Studio 17 2022 vspath:C:\Program Files\Microsoft Visual Studio\2022\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2022 rx:ON tls:ON upnp:ON vs:Visual Studio 17 2022 vspath:C:\Program Files\Microsoft Visual Studio\2022\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:ON os:2022 rx:ON tls:ON upnp:ON vs:Visual Studio 17 2022 vspath:C:\Program Files\Microsoft Visual Studio\2022\Enterprise]) (push) Has been cancelled
C/C++ CI / build-macos (push) Has been cancelled
C/C++ CI / build-macos-aarch64 (push) Has been cancelled
C/C++ CI / build-freebsd (map[architecture:x86-64 host:ubuntu-latest name:freebsd version:13.3]) (push) Has been cancelled
C/C++ CI / build-openbsd (map[architecture:x86-64 host:ubuntu-latest name:openbsd version:7.4]) (push) Has been cancelled
clang-tidy / clang-tidy (push) Has been cancelled
Code coverage / coverage (push) Has been cancelled
Microsoft C++ Code Analysis / Analyze (push) Has been cancelled
source-snapshot / source-snapshot (push) Failing after 3s
CodeQL / Analyze (cpp) (push) Failing after 14m7s
cppcheck / cppcheck-ubuntu (push) Failing after 7m20s
Sync test / sync-test-ubuntu-tsan (push) Failing after 12m6s
Sync test / sync-test-ubuntu-msan (push) Failing after 17m56s
Sync test / sync-test-ubuntu-ubsan (push) Failing after 12m18s
Sync test / sync-test-ubuntu-asan (push) Failing after 12m9s
cppcheck / cppcheck-windows (push) Has been cancelled
Sync test / sync-test-macos (map[flags: os:macos-15-intel]) (push) Has been cancelled
Sync test / sync-test-macos (map[flags:-target arm64-apple-macos-11 os:macos-15]) (push) Has been cancelled
Sync test / sync-test-windows-debug-asan (push) Has been cancelled
Sync test / sync-test-windows-leaks (push) Has been cancelled
94 lines
2.1 KiB
C
94 lines
2.1 KiB
C
/* Copyright (c) 2022 tevador <tevador@gmail.com>
|
|
*
|
|
* This file is part of mx25519, which is released under LGPLv3.
|
|
* See LICENSE for full license details.
|
|
*/
|
|
|
|
#include "platform.h"
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdbool.h>
|
|
#include <math.h>
|
|
|
|
#include <mx25519.h>
|
|
|
|
#ifdef _DEBUG
|
|
#define BENCH_LOOPS 10
|
|
#else
|
|
#define BENCH_LOOPS 100000
|
|
#endif
|
|
|
|
typedef double bench_func();
|
|
|
|
static const mx25519_privkey test_key = { {
|
|
102, 66, 236, 240, 6, 149, 92, 7, 43, 107, 163, 255, 64, 145, 5, 203,
|
|
230, 54, 147, 234, 197, 5, 215, 214, 124, 189, 226, 219, 235, 71, 20, 254 } };
|
|
|
|
double bench_impl(mx25519_type type) {
|
|
const mx25519_impl* impl = mx25519_select_impl(type);
|
|
|
|
if (impl == NULL) {
|
|
return NAN;
|
|
}
|
|
|
|
mx25519_pubkey result = { { 9 } };
|
|
|
|
uint64_t elapsed = 0;
|
|
uint64_t start = mx25519_cpu_cycles();
|
|
for (uint32_t i = 0; i < BENCH_LOOPS; ++i) {
|
|
mx25519_scmul_key(impl, &result, &test_key, &result);
|
|
}
|
|
uint64_t end = mx25519_cpu_cycles();
|
|
elapsed += (end - start);
|
|
|
|
return elapsed / (double)BENCH_LOOPS;
|
|
}
|
|
|
|
double bench_portable() {
|
|
return bench_impl(MX25519_TYPE_PORTABLE);
|
|
}
|
|
|
|
double bench_arm64() {
|
|
return bench_impl(MX25519_TYPE_ARM64);
|
|
}
|
|
|
|
double bench_amd64() {
|
|
return bench_impl(MX25519_TYPE_AMD64);
|
|
}
|
|
|
|
double bench_amd64x() {
|
|
return bench_impl(MX25519_TYPE_AMD64X);
|
|
}
|
|
|
|
static void run_bench(const char* name, bench_func* func) {
|
|
printf(" %-40s ... ", name);
|
|
double cycles = func();
|
|
if (isnan(cycles)) {
|
|
printf("N/A\n");
|
|
}
|
|
else {
|
|
printf("%.0f cycles/op.\n", cycles);
|
|
}
|
|
}
|
|
|
|
#define RUN_BENCH(x) run_bench(#x, &x)
|
|
|
|
int main(int argc, const char* argv[]) {
|
|
|
|
double wall_start = mx25519_wall_clock();
|
|
uint64_t cpu_start = mx25519_cpu_cycles();
|
|
|
|
RUN_BENCH(bench_portable);
|
|
RUN_BENCH(bench_arm64);
|
|
RUN_BENCH(bench_amd64);
|
|
RUN_BENCH(bench_amd64x);
|
|
|
|
double wall_end = mx25519_wall_clock();
|
|
uint64_t cpu_end = mx25519_cpu_cycles();
|
|
|
|
printf("\nCPU timer runs at %.3f MHz\n", (cpu_end - cpu_start) / (wall_end - wall_start) / 1e6);
|
|
|
|
return 0;
|
|
}
|