-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
twitch: add benchmark for payload decoding
1 parent
fd5f439
commit 72eb582
Showing
9 changed files
with
97 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package eventsub | ||
|
||
import ( | ||
"embed" | ||
"testing" | ||
|
||
"github.com/go-json-experiment/json" | ||
) | ||
|
||
//go:embed testdata/*.message.json | ||
var messages embed.FS | ||
|
||
func BenchmarkEventExtra(b *testing.B) { | ||
cases := []struct { | ||
name string | ||
file string | ||
}{ | ||
{ | ||
name: "keepalive", | ||
file: "keepalive.message.json", | ||
}, | ||
{ | ||
name: "notification-payload", | ||
file: "notification-payload.message.json", | ||
}, | ||
} | ||
for _, c := range cases { | ||
b.Run(c.name, func(b *testing.B) { | ||
p, err := messages.ReadFile("testdata/" + c.file) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
b.ReportAllocs() | ||
b.ResetTimer() | ||
for range b.N { | ||
var m message | ||
if err := json.Unmarshal(p, &m); err != nil { | ||
b.Error(err) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"metadata": { | ||
"message_id": "84c1e79a-2a4b-4c13-ba0b-4312293e9308", | ||
"message_type": "session_keepalive", | ||
"message_timestamp": "2023-07-19T10:11:12.634234626Z" | ||
}, | ||
"payload": {} | ||
} |
35 changes: 35 additions & 0 deletions
35
twitch/eventsub/testdata/notification-payload.message.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"metadata": { | ||
"message_id": "befa7b53-d79d-478f-86b9-120f112b044e", | ||
"message_type": "notification", | ||
"message_timestamp": "2022-11-16T10:11:12.464757833Z", | ||
"subscription_type": "channel.follow", | ||
"subscription_version": "1" | ||
}, | ||
"payload": { | ||
"subscription": { | ||
"id": "f1c2a387-161a-49f9-a165-0f21d7a4e1c4", | ||
"status": "enabled", | ||
"type": "channel.follow", | ||
"version": "1", | ||
"cost": 1, | ||
"condition": { | ||
"broadcaster_user_id": "12826" | ||
}, | ||
"transport": { | ||
"method": "websocket", | ||
"session_id": "AQoQexAWVYKSTIu4ec_2VAxyuhAB" | ||
}, | ||
"created_at": "2022-11-16T10:11:12.464757833Z" | ||
}, | ||
"event": { | ||
"user_id": "1337", | ||
"user_login": "awesome_user", | ||
"user_name": "Awesome_User", | ||
"broadcaster_user_id": "12826", | ||
"broadcaster_user_login": "twitch", | ||
"broadcaster_user_name": "Twitch", | ||
"followed_at": "2023-07-15T18:16:11.17106713Z" | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters