#![allow(incomplete_features)] #![feature(generic_const_exprs)] #![feature(const_trait_impl)] use criterion::{black_box, criterion_group, criterion_main, Criterion}; use cryptix_bigint::bigint; use cryptix_field::Element; use cryptix_field::field::montgomery::MontgomeryOps; use cryptix_field::field::primefield::FpElement; use cryptix_bn254::galoisfield::fp2::Fp2Element; use cryptix_bn254::galoisfield::U256; use cryptix_bn254::galoisfield::fp4::Fp4Element; use criterion_cycles_per_byte::CyclesPerByte; fn bench_fp2(c: &mut Criterion) { c.bench_function("bench fp2 addition", |b| { let x = Fp2Element( FpElement(Element::new(bigint!(U256, "206743e9b42b2cba7d527ee9b3284b03ffbd0bd7cd0aa20190ec5173cf9f5fa3"))), FpElement(Element::new(bigint!(U256, "110a06573d3face930d8722a9bbe8584814a795afc1eceb391c5cf229d09d3b0"))) ); let y = Fp2Element( FpElement(Element::new(bigint!(U256, "1d4edbc4972a57dd6af4c6e1cfededccdb6a46e7ffc8913306bb32fa3e1f19f2"))), FpElement(Element::new(bigint!(U256, "07482f3cf322f298cfa2b51eac13e3d8d37683e994faa78d979cbc5feed461a3"))) ); b.iter(|| black_box(x + y)) }); c.bench_function("bench fp2 montgomery multiplication", |b| { let x = Fp2Element( FpElement(Element::new(bigint!(U256, "206743e9b42b2cba7d527ee9b3284b03ffbd0bd7cd0aa20190ec5173cf9f5fa3"))), FpElement(Element::new(bigint!(U256, "110a06573d3face930d8722a9bbe8584814a795afc1eceb391c5cf229d09d3b0"))) ); let y = Fp2Element( FpElement(Element::new(bigint!(U256, "1d4edbc4972a57dd6af4c6e1cfededccdb6a46e7ffc8913306bb32fa3e1f19f2"))), FpElement(Element::new(bigint!(U256, "07482f3cf322f298cfa2b51eac13e3d8d37683e994faa78d979cbc5feed461a3"))) ); b.iter(|| black_box(x.mont_mul(y))) }); c.bench_function("bench fp4 mul s", |b| { let x = Fp2Element( FpElement(Element::new(bigint!(U256, "206743e9b42b2cba7d527ee9b3284b03ffbd0bd7cd0aa20190ec5173cf9f5fa3"))), FpElement(Element::new(bigint!(U256, "110a06573d3face930d8722a9bbe8584814a795afc1eceb391c5cf229d09d3b0"))) ); let y = Fp2Element( FpElement(Element::new(bigint!(U256, "1d4edbc4972a57dd6af4c6e1cfededccdb6a46e7ffc8913306bb32fa3e1f19f2"))), FpElement(Element::new(bigint!(U256, "07482f3cf322f298cfa2b51eac13e3d8d37683e994faa78d979cbc5feed461a3"))) ); let t = Fp4Element(x, y); b.iter(|| black_box(t.mul_s())) }); c.bench_function("bench fp2 montgomery square", |b| { let x = Fp2Element( FpElement(Element::new(bigint!(U256, "206743e9b42b2cba7d527ee9b3284b03ffbd0bd7cd0aa20190ec5173cf9f5fa3"))), FpElement(Element::new(bigint!(U256, "110a06573d3face930d8722a9bbe8584814a795afc1eceb391c5cf229d09d3b0"))) ); b.iter(|| black_box(x.mont_sqr())) }); c.bench_function("bench fp2 montgomery inversion", |b| { let x = Fp2Element( FpElement(Element::new(bigint!(U256, "206743e9b42b2cba7d527ee9b3284b03ffbd0bd7cd0aa20190ec5173cf9f5fa3"))), FpElement(Element::new(bigint!(U256, "110a06573d3face930d8722a9bbe8584814a795afc1eceb391c5cf229d09d3b0"))) ); b.iter(|| black_box(x.mont_inv())) }); c.bench_function("bench fp2 mul xi", |b| { let x = Fp2Element( FpElement(Element::new(bigint!(U256, "206743e9b42b2cba7d527ee9b3284b03ffbd0bd7cd0aa20190ec5173cf9f5fa3"))), FpElement(Element::new(bigint!(U256, "110a06573d3face930d8722a9bbe8584814a795afc1eceb391c5cf229d09d3b0"))) ); b.iter(|| black_box(x.mul_xi())) }); } criterion_group!( name = fp2_cycle_benches; config = Criterion::default().with_measurement(CyclesPerByte); targets = bench_fp2 ); criterion_main!(fp2_cycle_benches);