Skip to content

Commit

Permalink
chore: Add base benchmark for internal/function (#751)
Browse files Browse the repository at this point in the history
* chore: Add base benchmark for internal/function

* update comment
  • Loading branch information
Zheaoli authored Jan 2, 2024
1 parent 8406d8d commit 0f3a45f
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions internal/function/function_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package function

import (
"testing"

"RedisShake/internal/config"
"RedisShake/internal/entry"
)

// BenchmarkRunFunction is a benchmark for RunFunction
// Command is `go test -benchmem -bench="RunFunction$" -count=5 RedisShake/internal/function`
// Output is:
//
// BenchmarkRunFunction-16 6741 182470 ns/op 234715 B/op 1079 allocs/op
// BenchmarkRunFunction-16 7443 174567 ns/op 234710 B/op 1079 allocs/op
// BenchmarkRunFunction-16 7101 178651 ns/op 234711 B/op 1079 allocs/op
// BenchmarkRunFunction-16 6856 164739 ns/op 234722 B/op 1079 allocs/op
// BenchmarkRunFunction-16 6804 174768 ns/op 234713 B/op 1079 allocs/op
func BenchmarkRunFunction(b *testing.B) {
config.Opt = config.ShakeOptions{
Function: `
local prefix = "mlpSummary:"
local prefix_len = #prefix
if KEYS[1] == nil then
return
end
if KEYS[1] == "" then
return
end
if string.sub(KEYS[1], 1, prefix_len) ~= prefix then
return
end
shake.call(DB, ARGV)
`,
}
Init()
e := &entry.Entry{
DbId: 0,
Argv: []string{"set", "mlpSummary:1", "1"},
CmdName: "set",
Group: "default",
Keys: []string{"mlpSummary:1"},
KeyIndexes: []int{1},
Slots: []int{0},
SerializedSize: 32,
}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
RunFunction(e)
}
}

0 comments on commit 0f3a45f

Please sign in to comment.