~bigbes/tarantool

tarantool-protobuf

ref: 2df86386f587e8b84867c9f144bd76a801c3a9d6 tarantool-protobuf/bench/go/fixtures.go -rw-r--r-- 2.5 KiB
2df86386 — Eugene Blikh beads: close drm (encode/decode B/op floor investigation) 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Payload builders that mirror bench/bench.lua so msg sizes and shapes
// match across runtimes. Same field set + field numbers as the Lua
// build_person_payload / build_proto2_payload helpers, so encoded byte
// lengths land within a byte or two for the same target size.
package bench

import (
	"fmt"
	"strings"

	hellopb "github.com/tarantool-protobuf/bench/go/pb/hellopb"
	proto2pb "github.com/tarantool-protobuf/bench/go/pb/proto2pb"
	"google.golang.org/protobuf/proto"
)

type SizeSpec struct {
	Label  string
	Target int
}

var PersonSizes = []SizeSpec{
	{"10B", 10},
	{"100B", 100},
	{"1KB", 1024},
	{"10KB", 10240},
	{"100KB", 102400},
}

var Proto2Sizes = []SizeSpec{
	{"min", 0},
	{"mid", 1024},
}

func BuildPerson(target int) *hellopb.Person {
	if target <= 10 {
		return &hellopb.Person{Name: "bigbes", Age: 42}
	}
	if target <= 100 {
		return &hellopb.Person{
			Name: strings.Repeat("a", target-10),
			Age:  42,
		}
	}
	const perEmail = 36
	const fixedBytes = 80
	nEmails := (target - fixedBytes) / perEmail
	if nEmails < 1 {
		nEmails = 1
	}
	p := &hellopb.Person{
		Name: "bigbes",
		Age:  42,
		Address: &hellopb.Address{
			Street: "1 Main St",
			City:   "Springfield",
			Zip:    12345,
		},
		LuckyNumbers: []int32{7, 13, 21, 42, 99},
		Emails:       make([]string, nEmails),
	}
	for i := 0; i < nEmails; i++ {
		p.Emails[i] = strings.Repeat("e", 28) + fmt.Sprintf("%04d", i+1)
	}
	return p
}

func BuildProto2(target int) *proto2pb.BenchPayload {
	if target <= 0 {
		id := int32(7)
		m := &proto2pb.BenchPayload{Id: &id}
		proto.SetExtension(m, proto2pb.E_ExtCount, int32(42))
		return m
	}
	const nTags = 16
	const perTag = 30
	tags := make([]string, nTags)
	for i := 0; i < nTags; i++ {
		tags[i] = strings.Repeat("t", perTag-2) + fmt.Sprintf("%02d", i+1)
	}
	lucky := make([]int32, 8)
	for i := 0; i < 8; i++ {
		lucky[i] = int32(1000 + i + 1)
	}
	id := int32(7)
	name := "bench"
	retries := int32(9)
	innerKey := strings.Repeat("k", 16)
	innerWeight := int32(3)
	latency := int32(1234567)
	attempts := int32(4)
	m := &proto2pb.BenchPayload{
		Id:           &id,
		Name:         &name,
		Retries:      &retries,
		LuckyNumbers: lucky,
		Tags:         tags,
		Inner: &proto2pb.BenchPayload_Inner{
			Key:    &innerKey,
			Weight: &innerWeight,
		},
		Stats: &proto2pb.BenchPayload_Stats{
			LatencyNs: &latency,
			Attempts:  &attempts,
		},
	}
	proto.SetExtension(m, proto2pb.E_ExtCount, int32(99))
	proto.SetExtension(m, proto2pb.E_ExtLabel, strings.Repeat("x", 32))
	return m
}