Skip to content

Commit

Permalink
add BenchmarkUint512DivModByUint256
Browse files Browse the repository at this point in the history
  • Loading branch information
greged93 committed Nov 19, 2023
1 parent ae394fc commit 9f47b89
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions pkg/hintrunner/hint_bechmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9f47b89

Please sign in to comment.