-
Notifications
You must be signed in to change notification settings - Fork 911
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* template: add parse benchmarks Taken from the yagpdb-cc repository. To avoid licensing issues, I only used programs written by me. Baseline performance: name time/op Parse/lorem_ipsum-4 2.01µs ± 7% Parse/short-4 70.2µs ± 1% Parse/medium-4 165µs ± 1% Parse/long-4 517µs ± 1% Parse/very-long-4 1.79ms ± 1% name alloc/op Parse/lorem_ipsum-4 1.23kB ± 0% Parse/short-4 5.48kB ± 0% Parse/medium-4 12.7kB ± 0% Parse/long-4 35.3kB ± 0% Parse/very-long-4 113kB ± 0% name allocs/op Parse/lorem_ipsum-4 12.0 ± 0% Parse/short-4 109 ± 0% Parse/medium-4 298 ± 0% Parse/long-4 779 ± 0% Parse/very-long-4 2.61k ± 0% * template: port upstream changes Notably, this includes https://go-review.googlesource.com/c/go/+/421883, which changes the lexer to not spawn a new goroutine. name old time/op new time/op delta Parse/lorem_ipsum-4 2.01µs ± 7% 0.73µs ± 2% -63.56% (p=0.000 n=7+8) Parse/short-4 70.2µs ± 1% 16.6µs ± 1% -76.32% (p=0.000 n=7+8) Parse/medium-4 165µs ± 1% 40µs ± 1% -75.74% (p=0.000 n=8+8) Parse/long-4 517µs ± 1% 123µs ± 1% -76.28% (p=0.000 n=8+7) Parse/very-long-4 1.79ms ± 1% 0.42ms ± 1% -76.81% (p=0.000 n=8+8) name old alloc/op new alloc/op delta Parse/lorem_ipsum-4 1.23kB ± 0% 1.16kB ± 0% -5.56% (p=0.000 n=8+8) Parse/short-4 5.48kB ± 0% 5.42kB ± 0% -1.17% (p=0.000 n=8+8) Parse/medium-4 12.7kB ± 0% 12.6kB ± 0% -0.51% (p=0.000 n=8+8) Parse/long-4 35.3kB ± 0% 35.3kB ± 0% -0.17% (p=0.000 n=8+8) Parse/very-long-4 113kB ± 0% 113kB ± 0% -0.05% (p=0.000 n=8+8) name old allocs/op new allocs/op delta Parse/lorem_ipsum-4 12.0 ± 0% 10.0 ± 0% -16.67% (p=0.000 n=8+8) Parse/short-4 109 ± 0% 107 ± 0% -1.83% (p=0.000 n=8+8) Parse/medium-4 298 ± 0% 296 ± 0% -0.67% (p=0.000 n=8+8) Parse/long-4 779 ± 0% 777 ± 0% -0.26% (p=0.000 n=8+8) Parse/very-long-4 2.61k ± 0% 2.61k ± 0% -0.08% (p=0.000 n=8+8) * template: add ASCII fast path for lexer.next lexer.next is a hot function, as demonstrated by profiling. Most programs will consist of ASCII characters only, which we can optimize for. Ideally DecodeRuneInString would be inlined here and this wouldn't be a problem at all, but that won't be the case until golang/go#31666 is resolved. name old time/op new time/op delta Parse/lorem_ipsum-4 733ns ± 2% 733ns ± 2% ~ (p=0.933 n=8+8) Parse/short-4 16.6µs ± 1% 15.5µs ± 2% -6.75% (p=0.000 n=8+8) Parse/medium-4 40.1µs ± 1% 38.7µs ± 1% -3.51% (p=0.000 n=8+8) Parse/long-4 123µs ± 1% 115µs ± 1% -5.86% (p=0.001 n=7+7) Parse/very-long-4 416µs ± 1% 396µs ± 1% -4.70% (p=0.000 n=8+8) name old alloc/op new alloc/op delta Parse/lorem_ipsum-4 1.16kB ± 0% 1.16kB ± 0% ~ (all equal) Parse/short-4 5.42kB ± 0% 5.42kB ± 0% ~ (all equal) Parse/medium-4 12.6kB ± 0% 12.6kB ± 0% ~ (all equal) Parse/long-4 35.3kB ± 0% 35.3kB ± 0% ~ (all equal) Parse/very-long-4 113kB ± 0% 113kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta Parse/lorem_ipsum-4 10.0 ± 0% 10.0 ± 0% ~ (all equal) Parse/short-4 107 ± 0% 107 ± 0% ~ (all equal) Parse/medium-4 296 ± 0% 296 ± 0% ~ (all equal) Parse/long-4 777 ± 0% 777 ± 0% ~ (all equal) Parse/very-long-4 2.61k ± 0% 2.61k ± 0% ~ (all equal) * template: preallocate for 4 args in CommandNode CommandNode.append and by extension runtime.growslice was showing up more than expected during profiling. Allocate enough space for four arguments up front so we don't need to reallocate as much. Although this doesn't benefit performance much, it does have a clear positive effect on memory usage. name old time/op new time/op delta Parse/lorem_ipsum-4 733ns ± 2% 728ns ± 2% ~ (p=0.315 n=8+8) Parse/short-4 15.5µs ± 2% 15.2µs ± 1% -2.12% (p=0.001 n=8+8) Parse/medium-4 38.7µs ± 1% 38.0µs ± 1% -1.99% (p=0.000 n=8+8) Parse/long-4 115µs ± 1% 117µs ± 5% ~ (p=0.281 n=7+8) Parse/very-long-4 396µs ± 1% 400µs ± 1% +1.02% (p=0.002 n=8+8) name old alloc/op new alloc/op delta Parse/lorem_ipsum-4 1.16kB ± 0% 1.16kB ± 0% ~ (all equal) Parse/short-4 5.42kB ± 0% 5.08kB ± 0% -6.20% (p=0.000 n=8+8) Parse/medium-4 12.6kB ± 0% 12.7kB ± 0% +0.51% (p=0.000 n=8+8) Parse/long-4 35.3kB ± 0% 34.4kB ± 0% -2.58% (p=0.000 n=8+8) Parse/very-long-4 113kB ± 0% 110kB ± 0% -2.37% (p=0.000 n=8+8) name old allocs/op new allocs/op delta Parse/lorem_ipsum-4 10.0 ± 0% 10.0 ± 0% ~ (all equal) Parse/short-4 107 ± 0% 93 ± 0% -13.08% (p=0.000 n=8+8) Parse/medium-4 296 ± 0% 276 ± 0% -6.76% (p=0.000 n=8+8) Parse/long-4 777 ± 0% 705 ± 0% -9.27% (p=0.000 n=8+8) Parse/very-long-4 2.61k ± 0% 2.35k ± 0% -9.77% (p=0.000 n=8+8)
- Loading branch information
Showing
10 changed files
with
685 additions
and
150 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,66 @@ | ||
{{/* | ||
Views information about the server. | ||
See <https://yagpdb-cc.github.io/info/server> for more information. | ||
|
||
Author: jo3-l <https://github.com/jo3-l> | ||
*/}} | ||
|
||
{{ $icon := "" }} | ||
{{ $name := printf "%s (%d)" .Guild.Name .Guild.ID }} | ||
{{ if .Guild.Icon }} | ||
{{ $ext := "webp" }} | ||
{{ if eq (slice .Guild.Icon 0 2) "a_" }} {{ $ext = "gif" }} {{ end }} | ||
{{ $icon = printf "https://cdn.discordapp.com/icons/%d/%s.%s" .Guild.ID .Guild.Icon $ext }} | ||
{{ end }} | ||
|
||
{{ $owner := userArg .Guild.OwnerID }} | ||
{{ $levels := cslice | ||
"None: Unrestricted" | ||
"Low: Must have a verified email on their Discord account." | ||
"Medium: Must also be registered on Discord for longer than 5 minutes." | ||
"(╯°□°)╯︵ ┻━┻: Must also be a member of this server for longer than 10 minutes." | ||
"┻━┻ ミヽ(ಠ益ಠ)ノ彡┻━┻: Must have a verified phone on their Discord account." | ||
}} | ||
{{ $afk := "n/a" }} | ||
{{ if .Guild.AfkChannelID }} | ||
{{ $afk = printf "**Channel:** <#%d> (%d)\n**Timeout:** %s" | ||
.Guild.AfkChannelID | ||
.Guild.AfkChannelID | ||
(humanizeDurationSeconds (toDuration (mult .Guild.AfkTimeout .TimeSecond))) | ||
}} | ||
{{ end }} | ||
{{ $embedsEnabled := "No" }} | ||
{{ if .Guild.WidgetEnabled }} {{ $embedsEnabled = "Yes" }} {{ end }} | ||
{{ $createdAt := div .Guild.ID 4194304 | add 1420070400000 | mult 1000000 | toDuration | (newDate 1970 1 1 0 0 0).Add }} | ||
|
||
{{ $infoEmbed := cembed | ||
"author" (sdict "name" $name "icon_url" $icon) | ||
"color" 14232643 | ||
"thumbnail" (sdict "url" $icon) | ||
"fields" (cslice | ||
(sdict "name" "Verification Level" "value" (index $levels .Guild.VerificationLevel)) | ||
(sdict "name" "Region" "value" .Guild.Region) | ||
(sdict "name" "Members" "value" (printf "**• Total:** %d Members\n**• Online:** %d Members" .Guild.MemberCount onlineCount)) | ||
(sdict "name" "Roles" "value" (printf "**• Total:** %d\nUse `-listroles` to list all roles." (len .Guild.Roles))) | ||
(sdict "name" "Owner" "value" (printf "%s (%d)" $owner.String $owner.ID)) | ||
(sdict "name" "AFK" "value" $afk) | ||
(sdict "name" "Embeds Enabled" "value" $embedsEnabled) | ||
) | ||
"footer" (sdict "text" "Created at") | ||
"timestamp" $createdAt | ||
}} | ||
|
||
{{ if .CmdArgs }} | ||
{{ if eq (index .CmdArgs 0) "icon" }} | ||
{{ sendMessage nil (cembed | ||
"author" (sdict "name" $name "icon_url" $icon) | ||
"title" "Server Icon" | ||
"color" 14232643 | ||
"image" (sdict "url" $icon) | ||
) }} | ||
{{ else }} | ||
{{ sendMessage nil $infoEmbed }} | ||
{{ end }} | ||
{{ else }} | ||
{{ sendMessage nil $infoEmbed }} | ||
{{ end }} |
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,3 @@ | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. | ||
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. | ||
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. |
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,30 @@ | ||
{{/* | ||
Separates predefined flags from positional arguments within input. | ||
See <https://yagpdb-cc.github.io/code-snippets/parse-flags> for more information. | ||
|
||
Licensed under the terms of the Unlicense. | ||
Author: jo3-l <https://github.com/jo3-l> | ||
*/}} | ||
|
||
{{define "parseFlags"}} | ||
{{.Set "Out" (sdict | ||
"Positional" (cslice) | ||
"Flags" (dict) | ||
"Switches" (dict) | ||
)}} | ||
|
||
{{$curFlag := ""}} | ||
{{$lastIdx := sub (len .Args) 1}} | ||
{{range $i, $arg := .Args}} | ||
{{- if $curFlag}} | ||
{{- $.Out.Flags.Set $curFlag $arg}} | ||
{{- $curFlag = ""}} | ||
{{- else if and ($id := $.Flags.Get $arg) (ne $i $lastIdx)}} | ||
{{- $curFlag = $id}} | ||
{{- else if $id := $.Switches.Get $arg}} | ||
{{- $.Out.Switches.Set $id true}} | ||
{{- else}} | ||
{{- $.Out.Set "Positional" ($.Out.Positional.Append $arg)}} | ||
{{- end -}} | ||
{{end}} | ||
{{end}} |
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,15 @@ | ||
{{/* | ||
Displays a random color. | ||
See <https://yagpdb-cc.github.io/utilities/random-color> for more information. | ||
|
||
Author: jo3-l <https://github.com/jo3-l> | ||
*/}} | ||
|
||
{{ $dec := randInt 0 16777216 }} | ||
{{ $hex := printf "%06x" $dec }} | ||
{{ sendMessage nil (cembed | ||
"title" "Random Color" | ||
"color" $dec | ||
"description" (printf "**Decimal:** %d\n**Hex:** #%s" $dec $hex) | ||
"thumbnail" (sdict "url" (printf "https://dummyimage.com/400x400/%s/%s" $hex $hex)) | ||
) }} |
Oops, something went wrong.