initial commit

This commit is contained in:
2024-08-01 23:42:30 +03:00
commit 09fef3c113
21 changed files with 931 additions and 0 deletions

View File

@@ -0,0 +1,134 @@
package main
import (
"context"
"testing"
"time"
"github.com/google/uuid"
"git.derfenix.pro/fenix/commander"
"git.derfenix.pro/fenix/commander/inmemorycache"
)
func BenchmarkServiceNoop(b *testing.B) {
ctx := context.Background()
cmd := commander.New(10)
c1 := GetName{UID: uuid.NewString()}
c2 := GetAddress{Input: &c1.Result}
commands := []commander.Command{&c1, &c2}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if err := cmd.Execute(ctx, "", commands...); err != nil {
_ = err
}
}
}
func BenchmarkServiceWithDelay(b *testing.B) {
ctx := context.Background()
cmd := commander.New(10)
c1 := GetName{UID: uuid.NewString(), Sleep: time.Microsecond * 100}
c2 := GetAddress{Input: &c1.Result}
commands := []commander.Command{&c1, &c2}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if err := cmd.Execute(ctx, "", commands...); err != nil {
_ = err
}
}
}
func BenchmarkServiceWithRollbackNoop(b *testing.B) {
ctx := context.Background()
cmd := commander.New(10)
c1 := GetName{UID: uuid.NewString()}
c2 := GetAddress{Input: &c1.Result}
commands := []commander.Command{&c1, &c2}
commands = append(commands, &GetAddress{Input: &c2.Result})
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if err := cmd.Execute(ctx, "", commands...); err != nil {
_ = err
}
}
}
func BenchmarkServiceWithRollbackWithDelay(b *testing.B) {
ctx := context.Background()
cmd := commander.New(10)
c1 := GetName{UID: uuid.NewString(), Sleep: time.Microsecond * 100}
c2 := GetAddress{Input: &c1.Result}
commands := []commander.Command{&c1, &c2}
commands = append(commands, &GetAddress{Input: &c2.Result})
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if err := cmd.Execute(ctx, "", commands...); err != nil {
_ = err
}
}
}
func BenchmarkServiceWithCacheNoop(b *testing.B) {
ctx := context.Background()
cmd := commander.New(10)
cmd = cmd.WithCache(inmemorycache.NewInMemoryCache())
c1 := GetName{UID: uuid.NewString()}
c2 := GetAddress{Input: &c1.Result}
commands := []commander.Command{&c1, &c2}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if err := cmd.Execute(ctx, "", commands...); err != nil {
_ = err
}
}
}
func BenchmarkServiceWithCacheWithDelay(b *testing.B) {
ctx := context.Background()
cmd := commander.New(10)
cmd = cmd.WithCache(inmemorycache.NewInMemoryCache())
c1 := GetName{UID: uuid.NewString(), Sleep: time.Microsecond * 100}
c2 := GetAddress{Input: &c1.Result}
commands := []commander.Command{&c1, &c2}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if err := cmd.Execute(ctx, "", commands...); err != nil {
_ = err
}
}
}