mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 13:22:56 +01:00
update go version so we can use the new benchmarking helper.
This commit is contained in:
parent
1b610ba318
commit
4dcadd4d88
@ -17,7 +17,7 @@ func BenchmarkParseMessage(b *testing.B) {
|
||||
messages := generateTestMessages(name)
|
||||
|
||||
b.Run("jsonstdlib", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
for _, msg := range messages {
|
||||
var v any
|
||||
stdlibjson.Unmarshal(unsafe.Slice(unsafe.StringData(msg), len(msg)), &v)
|
||||
@ -26,7 +26,7 @@ func BenchmarkParseMessage(b *testing.B) {
|
||||
})
|
||||
|
||||
b.Run("easyjson", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
for _, msg := range messages {
|
||||
_ = ParseMessage(msg)
|
||||
}
|
||||
@ -35,7 +35,7 @@ func BenchmarkParseMessage(b *testing.B) {
|
||||
|
||||
b.Run("sonic", func(b *testing.B) {
|
||||
smp := NewSonicMessageParser()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
for _, msg := range messages {
|
||||
_, _ = smp.ParseMessage(msg)
|
||||
}
|
||||
|
@ -104,13 +104,13 @@ func BenchmarkIDCheck(b *testing.B) {
|
||||
evt.Sign(GeneratePrivateKey())
|
||||
|
||||
b.Run("naïve", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
_ = evt.GetID() == evt.ID
|
||||
}
|
||||
})
|
||||
|
||||
b.Run("big brain", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
for b.Loop() {
|
||||
_ = evt.CheckID()
|
||||
}
|
||||
})
|
||||
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
||||
module github.com/nbd-wtf/go-nostr
|
||||
|
||||
go 1.23.1
|
||||
go 1.24.1
|
||||
|
||||
require (
|
||||
github.com/ImVexed/fasturl v0.0.0-20230304231329-4e41488060f3
|
||||
|
@ -129,26 +129,3 @@ func TestDoWorkTimeout(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkDoWork(b *testing.B) {
|
||||
if testing.Short() {
|
||||
b.Skip("too consuming for short mode")
|
||||
}
|
||||
for _, difficulty := range []int{8, 16, 24} {
|
||||
difficulty := difficulty
|
||||
b.Run(fmt.Sprintf("%dbits", difficulty), func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
event := &nostr.Event{
|
||||
Kind: nostr.KindTextNote,
|
||||
Content: "It's just me mining my own business",
|
||||
PubKey: "a48380f4cfcc1ad5378294fcac36439770f9c878dd880ffa94bb74ea54a6f243",
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
|
||||
defer cancel()
|
||||
if _, err := DoWork(ctx, *event, difficulty); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user