From 9f47b899c023535d1b43e91529edf03308772514 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Sun, 19 Nov 2023 14:39:14 +0100 Subject: [PATCH] add BenchmarkUint512DivModByUint256 --- pkg/hintrunner/hint_bechmark_test.go | 50 ++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/pkg/hintrunner/hint_bechmark_test.go b/pkg/hintrunner/hint_bechmark_test.go index 56155f97f..801eaf3a1 100644 --- a/pkg/hintrunner/hint_bechmark_test.go +++ b/pkg/hintrunner/hint_bechmark_test.go @@ -149,7 +149,7 @@ func BenchmarkLinearSplit(b *testing.B) { y: y, } - err := hint.Execute(vm) + err := hint.Execute(vm, nil) if err != nil { b.Error(err) break @@ -158,6 +158,52 @@ func BenchmarkLinearSplit(b *testing.B) { } } +func BenchmarkUint512DivModByUint256(b *testing.B) { + vm := defaultVirtualMachine() + vm.Context.Ap = 0 + vm.Context.Fp = 0 + + rand := defaultRandGenerator() + + var quotient0 ApCellRef = 1 + var quotient1 ApCellRef = 2 + var quotient2 ApCellRef = 3 + var quotient3 ApCellRef = 4 + var remainder0 ApCellRef = 5 + var remainder1 ApCellRef = 6 + + for i := 0; i < b.N; i++ { + dividend0 := Immediate(randomFeltElement(rand)) + dividend1 := Immediate(randomFeltElement(rand)) + dividend2 := Immediate(randomFeltElement(rand)) + dividend3 := Immediate(randomFeltElement(rand)) + divisor0 := Immediate(randomFeltElement(rand)) + divisor1 := Immediate(randomFeltElement(rand)) + + hint := Uint512DivModByUint256{ + dividend0, + dividend1, + dividend2, + dividend3, + divisor0, + divisor1, + quotient0, + quotient1, + quotient2, + quotient3, + remainder0, + remainder1, + } + + err := hint.Execute(vm, nil) + if err != nil { + b.Error(err) + break + } + vm.Context.Ap += 6 + } +} + func randomFeltElement(rand *rand.Rand) f.Element { b := [32]byte{} binary.BigEndian.PutUint64(b[24:32], rand.Uint64()) @@ -207,7 +253,7 @@ func BenchmarkUint256SquareRoot(b *testing.B) { sqrtMul2MinusRemainderGeU128: sqrtMul2MinusRemainderGeU128, } - err := hint.Execute(vm) + err := hint.Execute(vm, nil) if err != nil { b.Error(err) break