Skip to content

Commit

Permalink
[2/N] Chunk encoding optimization: bench mark the gnark based encoding (
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix authored Jul 11, 2024
1 parent 4dd73e2 commit 63c1d21
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions encoding/serialization_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package encoding_test

import (
"math/rand"
"testing"

"github.com/Layr-Labs/eigenda/encoding"
Expand Down Expand Up @@ -45,3 +46,74 @@ func TestSerDeserGnark(t *testing.T) {
assert.True(t, f.Coeffs[i].Equal(&c.Coeffs[i]))
}
}

func createFrames(b *testing.B, numFrames int) []encoding.Frame {
var XCoord, YCoord fp.Element
_, err := XCoord.SetString("21661178944771197726808973281966770251114553549453983978976194544185382599016")
assert.NoError(b, err)
_, err = YCoord.SetString("9207254729396071334325696286939045899948985698134704137261649190717970615186")
assert.NoError(b, err)
r := rand.New(rand.NewSource(2024))
numCoeffs := 64
frames := make([]encoding.Frame, numFrames)
for n := 0; n < numFrames; n++ {
frames[n].Proof = encoding.Proof{
X: XCoord,
Y: YCoord,
}
for i := 0; i < numCoeffs; i++ {
frames[n].Coeffs = append(frames[n].Coeffs, fr.NewElement(r.Uint64()))
}
}
return frames
}

func BenchmarkFrameGobSerialization(b *testing.B) {
numSamples := 64
frames := createFrames(b, numSamples)

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = frames[i%numSamples].Serialize()
}
}

func BenchmarkFrameGnarkSerialization(b *testing.B) {
numSamples := 64
frames := createFrames(b, numSamples)

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = frames[i%numSamples].SerializeGnark()
}
}

func BenchmarkFrameGobDeserialization(b *testing.B) {
numSamples := 64
frames := createFrames(b, numSamples)
bytes := make([][]byte, numSamples)
for n := 0; n < numSamples; n++ {
gob, _ := frames[n].Serialize()
bytes[n] = gob
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = new(encoding.Frame).Deserialize(bytes[i%numSamples])
}
}

func BenchmarkFrameGnarkDeserialization(b *testing.B) {
numSamples := 64
frames := createFrames(b, numSamples)
bytes := make([][]byte, numSamples)
for n := 0; n < numSamples; n++ {
gnark, _ := frames[n].SerializeGnark()
bytes[n] = gnark
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = new(encoding.Frame).DeserializeGnark(bytes[i%numSamples])
}
}

0 comments on commit 63c1d21

Please sign in to comment.