Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bench.cpp] Add benchmarks for mul_avx, add_avx, and mul33c_avx #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions benchs/bench.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <benchmark/benchmark.h>
#include <iostream>

#include "../src/goldilocks_cubic_extension.hpp"
#include "../src/goldilocks_base_field.hpp"
#include "../src/poseidon_goldilocks.hpp"
#include "../src/poseidon_goldilocks_avx.hpp"
Expand All @@ -23,6 +24,46 @@
#define NPHASES_LDE 2
#define NBLOCKS 1

static void escape(void *p) {
asm volatile("" : : "g"(p): "memory");
}

static void BENCH_ADD_AVX(benchmark::State &state) {
__m256i a_;
__m256i b_;

// Benchmark
for (auto _ : state)
{
Goldilocks::add_avx(a_, a_, b_);
escape(&a_);
}
}

static void BENCH_MUL_AVX(benchmark::State &state) {
Goldilocks::Element a_ = Goldilocks::fromU64(9);
Goldilocks::Element b_ = Goldilocks::fromU64(10);

// Benchmark
for (auto _ : state)
{
Goldilocks::mul_avx(&a_, &a_, &b_);
escape(&a_);
}
}

static void BENCH_MUL33C_AVX(benchmark::State &state) {
Goldilocks::Element a_[12];
Goldilocks::Element b_[12];

// Benchmark
for (auto _ : state)
{
Goldilocks3::mul33c_avx(a_, a_, b_);
escape(a_);
}
}

static void POSEIDON_BENCH_FULL(benchmark::State &state)
{
uint64_t input_size = (uint64_t)NUM_HASHES * (uint64_t)SPONGE_WIDTH;
Expand Down Expand Up @@ -886,6 +927,18 @@ static void EXTENDEDPOL_BENCH(benchmark::State &state)
free(c);
}

BENCHMARK(BENCH_ADD_AVX)
->Unit(benchmark::kNanosecond)
->UseRealTime();

BENCHMARK(BENCH_MUL_AVX)
->Unit(benchmark::kNanosecond)
->UseRealTime();

BENCHMARK(BENCH_MUL33C_AVX)
->Unit(benchmark::kNanosecond)
->UseRealTime();

BENCHMARK(POSEIDON_BENCH_FULL)
->Unit(benchmark::kMicrosecond)
->DenseRange(omp_get_max_threads() / 2, omp_get_max_threads(), omp_get_max_threads() / 2)
Expand Down