How to use Name method of performance_test Package

Best Ginkgo code snippet using performance_test.Name

Run Ginkgo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

performance_test.go

Source: performance_test.go Github

copy
1// Copyright 2022 FishGoddess. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package main
16
17import (
18	"io/ioutil"
19	"os"
20	"path/filepath"
21	"testing"
22	//"time"
23
24	"github.com/go-logit/logit"
25	"github.com/go-logit/logit/core/appender"
26	//"github.com/rs/zerolog"
27	//"github.com/sirupsen/logrus"
28	//"go.uber.org/zap"
29	//"go.uber.org/zap/zapcore"
30)
31
32/*
33$ go test -v ./_examples/performance_test.go -bench=. -benchtime=1s
34
35BenchmarkLogitLoggerWithTextAppender-16    856958              1362 ns/op               0 B/op          0 allocs/op
36
37BenchmarkLogitLoggerWithJsonAppender-16    799759              1373 ns/op               0 B/op          0 allocs/op
38
39BenchmarkLogitLoggerWithFormat-16          666484              1740 ns/op              40 B/op          4 allocs/op
40
41BenchmarkZeroLogLogger-16                  922863              1244 ns/op               0 B/op          0 allocs/op
42
43BenchmarkZapLogger-16                      413701              2824 ns/op             897 B/op          8 allocs/op
44
45BenchmarkLogrusLogger-16                   105238             11474 ns/op            7411 B/op        128 allocs/op
46
47******************************************************************************************************************
48
49BenchmarkLogitFileWithTextAppender-16     631435              1751 ns/op             851 B/op          0 allocs/op
50
51BenchmarkLogitFileWithJsonAppender-16     599862              1768 ns/op             896 B/op          0 allocs/op
52
53BenchmarkLogitFileWithoutBuffer-16        148113              7773 ns/op               0 B/op          0 allocs/op
54
55BenchmarkZeroLogFile-16                   159962              7472 ns/op               0 B/op          0 allocs/op
56
57BenchmarkZapFile-16                       130405              9137 ns/op             897 B/op          8 allocs/op
58
59BenchmarkLogrusFile-16                     65202             18439 ns/op            7410 B/op        128 allocs/op
60*/
61
62const (
63	timeFormat = "2006-01-02 15:04:05"
64)
65
66// go test -v ./_examples/performance_test.go -bench=^BenchmarkLogitLoggerWithTextAppender$ -benchtime=1s
67func BenchmarkLogitLoggerWithTextAppender(b *testing.B) {
68	options := logit.Options()
69
70	logger := logit.NewLogger(
71		options.WithDebugLevel(),
72		options.WithAppender(appender.Text()),
73		options.WithWriter(ioutil.Discard, false),
74		options.WithTimeFormat(timeFormat),
75	)
76
77	logTask := func() {
78		logger.Debug("debug...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
79		logger.Info("info...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
80		logger.Warn("warning...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
81		logger.Error("error...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
82	}
83
84	b.ReportAllocs()
85	b.StartTimer()
86
87	for i := 0; i < b.N; i++ {
88		logTask()
89	}
90}
91
92// go test -v ./_examples/performance_test.go -bench=^BenchmarkLogitLoggerWithJsonAppender$ -benchtime=1s
93func BenchmarkLogitLoggerWithJsonAppender(b *testing.B) {
94	options := logit.Options()
95
96	logger := logit.NewLogger(
97		options.WithDebugLevel(),
98		options.WithAppender(appender.Json()),
99		options.WithWriter(ioutil.Discard, false),
100		options.WithTimeFormat(timeFormat),
101	)
102
103	logTask := func() {
104		logger.Debug("debug...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
105		logger.Info("info...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
106		logger.Warn("warning...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
107		logger.Error("error...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
108	}
109
110	b.ReportAllocs()
111	b.StartTimer()
112
113	for i := 0; i < b.N; i++ {
114		logTask()
115	}
116}
117
118// go test -v ./_examples/performance_test.go -bench=^BenchmarkLogitLoggerWithFormat$ -benchtime=1s
119func BenchmarkLogitLoggerWithFormat(b *testing.B) {
120	options := logit.Options()
121
122	logger := logit.NewLogger(
123		options.WithDebugLevel(),
124		options.WithAppender(appender.Text()),
125		options.WithWriter(ioutil.Discard, false),
126		options.WithTimeFormat(timeFormat),
127	)
128
129	logTask := func() {
130		logger.Debug("debug%s", "...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
131		logger.Info("info%s", "...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
132		logger.Warn("warning%s", "...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
133		logger.Error("error%s", "...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
134	}
135
136	b.ReportAllocs()
137	b.StartTimer()
138
139	for i := 0; i < b.N; i++ {
140		logTask()
141	}
142}
143
144//// go test -v ./_examples/performance_test.go -bench=^BenchmarkZeroLogLogger$ -benchtime=1s
145//func BenchmarkZeroLogLogger(b *testing.B) {
146//	zerolog.TimeFieldFormat = timeFormat
147//	logger := zerolog.New(&nopWriter{}).With().Timestamp().Logger()
148//
149//	logTask := func() {
150//		logger.Debug().Str("trace", "xxx").Int("id", 123).Float64("pi", 3.14).Msg("debug...")
151//		logger.Info().Str("trace", "xxx").Int("id", 123).Float64("pi", 3.14).Msg("info...")
152//		logger.Warn().Str("trace", "xxx").Int("id", 123).Float64("pi", 3.14).Msg("warning...")
153//		logger.Error().Str("trace", "xxx").Int("id", 123).Float64("pi", 3.14).Msg("error...")
154//	}
155//
156//	b.ReportAllocs()
157//	b.StartTimer()
158//
159//	for i := 0; i < b.N; i++ {
160//		logTask()
161//	}
162//}
163//
164//// go test -v ./_examples/performance_test.go -bench=^BenchmarkZapLogger$ -benchtime=1s
165//func BenchmarkZapLogger(b *testing.B) {
166//	config := zap.NewProductionEncoderConfig()
167//	config.EncodeTime = func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
168//		enc.AppendString(t.Format(timeFormat))
169//	}
170//	encoder := zapcore.NewJSONEncoder(config)
171//	nopWriteSyncer := zapcore.AddSync(&nopWriter{})
172//	core := zapcore.NewCore(encoder, nopWriteSyncer, zapcore.DebugLevel)
173//	logger := zap.New(core)
174//	defer logger.Sync()
175//
176//	logTask := func() {
177//		logger.Debug("debug...", zap.String("trace", "abcxxx"), zap.Int("id", 123), zap.Float64("pi", 3.14))
178//		logger.Info("info...", zap.String("trace", "abcxxx"), zap.Int("id", 123), zap.Float64("pi", 3.14))
179//		logger.Warn("warning...", zap.String("trace", "abcxxx"), zap.Int("id", 123), zap.Float64("pi", 3.14))
180//		logger.Error("error...", zap.String("trace", "abcxxx"), zap.Int("id", 123), zap.Float64("pi", 3.14))
181//	}
182//
183//	b.ReportAllocs()
184//	b.StartTimer()
185//
186//	for i := 0; i < b.N; i++ {
187//		logTask()
188//	}
189//}
190//
191//// go test -v ./_examples/performance_test.go -bench=^BenchmarkLogrusLogger$ -benchtime=1s
192//func BenchmarkLogrusLogger(b *testing.B) {
193//	logger := logrus.New()
194//	logger.SetOutput(&nopWriter{})
195//	logger.SetLevel(logrus.DebugLevel)
196//	logger.SetFormatter(&logrus.JSONFormatter{
197//		TimestampFormat: timeFormat,
198//	})
199//
200//	logTask := func() {
201//		logger.WithFields(map[string]interface{}{"trace": "xxx", "id": 123, "pi": 3.14}).Debug("debug...")
202//		logger.WithFields(map[string]interface{}{"trace": "xxx", "id": 123, "pi": 3.14}).Info("info...")
203//		logger.WithFields(map[string]interface{}{"trace": "xxx", "id": 123, "pi": 3.14}).Warn("warning...")
204//		logger.WithFields(map[string]interface{}{"trace": "xxx", "id": 123, "pi": 3.14}).Error("error...")
205//	}
206//
207//	b.ReportAllocs()
208//	b.StartTimer()
209//
210//	for i := 0; i < b.N; i++ {
211//		logTask()
212//	}
213//}
214
215// ******************************************************
216
217func createFileOf(filePath string) (*os.File, error) {
218	err := os.MkdirAll(filepath.Dir(filePath), 0644)
219	if err != nil {
220		return nil, err
221	}
222	return os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
223}
224
225// go test -v ./_examples/performance_test.go -bench=^BenchmarkLogitFileWithTextAppender$ -benchtime=1s
226func BenchmarkLogitFileWithTextAppender(b *testing.B) {
227	file, _ := createFileOf("Z:/" + b.Name() + ".log")
228	defer file.Close()
229
230	options := logit.Options()
231	logger := logit.NewLogger(
232		options.WithDebugLevel(),
233		options.WithAppender(appender.Text()),
234		options.WithWriter(file, true),
235		options.WithTimeFormat(timeFormat),
236	)
237	defer logger.Close()
238
239	logTask := func() {
240		logger.Debug("debug...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
241		logger.Info("info...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
242		logger.Warn("warning...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
243		logger.Error("error...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
244	}
245
246	b.ReportAllocs()
247	b.StartTimer()
248
249	for i := 0; i < b.N; i++ {
250		logTask()
251	}
252}
253
254// go test -v ./_examples/performance_test.go -bench=^BenchmarkLogitFileWithJsonAppender$ -benchtime=1s
255func BenchmarkLogitFileWithJsonAppender(b *testing.B) {
256	file, _ := createFileOf("Z:/" + b.Name() + ".log")
257	defer file.Close()
258
259	options := logit.Options()
260	logger := logit.NewLogger(
261		options.WithDebugLevel(),
262		options.WithAppender(appender.Json()),
263		options.WithWriter(file, true),
264		options.WithTimeFormat(timeFormat),
265	)
266	defer logger.Close()
267
268	logTask := func() {
269		logger.Debug("debug...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
270		logger.Info("info...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
271		logger.Warn("warning...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
272		logger.Error("error...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
273	}
274
275	b.ReportAllocs()
276	b.StartTimer()
277
278	for i := 0; i < b.N; i++ {
279		logTask()
280	}
281}
282
283// go test -v ./_examples/performance_test.go -bench=^BenchmarkLogitFileWithoutBuffer$ -benchtime=1s
284func BenchmarkLogitFileWithoutBuffer(b *testing.B) {
285	file, _ := createFileOf("Z:/" + b.Name() + ".log")
286	defer file.Close()
287
288	options := logit.Options()
289	logger := logit.NewLogger(
290		options.WithDebugLevel(),
291		options.WithAppender(appender.Text()),
292		options.WithWriter(file, false),
293		options.WithTimeFormat(timeFormat),
294	)
295
296	logTask := func() {
297		logger.Debug("debug...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
298		logger.Info("info...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
299		logger.Warn("warning...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
300		logger.Error("error...").String("trace", "xxx").Int("id", 123).Float64("pi", 3.14).End()
301	}
302
303	b.ReportAllocs()
304	b.StartTimer()
305
306	for i := 0; i < b.N; i++ {
307		logTask()
308	}
309}
310
311//// go test -v ./_examples/performance_test.go -bench=^BenchmarkZeroLogFile$ -benchtime=1s
312//func BenchmarkZeroLogFile(b *testing.B) {
313//	file, _ := createFileOf("Z:/" + b.Name() + ".log")
314//	zerolog.TimeFieldFormat = timeFormat
315//	logger := zerolog.New(file).With().Timestamp().Logger()
316//
317//	logTask := func() {
318//		logger.Debug().Str("trace", "xxx").Int("id", 123).Float64("pi", 3.14).Msg("debug...")
319//		logger.Info().Str("trace", "xxx").Int("id", 123).Float64("pi", 3.14).Msg("info...")
320//		logger.Warn().Str("trace", "xxx").Int("id", 123).Float64("pi", 3.14).Msg("warning...")
321//		logger.Error().Str("trace", "xxx").Int("id", 123).Float64("pi", 3.14).Msg("error...")
322//	}
323//
324//	b.ReportAllocs()
325//	b.StartTimer()
326//
327//	for i := 0; i < b.N; i++ {
328//		logTask()
329//	}
330//}
331//
332//// go test -v ./_examples/performance_test.go -bench=^BenchmarkZapFile$ -benchtime=1s
333//func BenchmarkZapFile(b *testing.B) {
334//	file, _ := createFileOf("Z:/" + b.Name() + ".log")
335//	config := zap.NewProductionEncoderConfig()
336//	config.EncodeTime = func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
337//		enc.AppendString(t.Format(timeFormat))
338//	}
339//	encoder := zapcore.NewJSONEncoder(config)
340//	writeSyncer := zapcore.AddSync(file)
341//	core := zapcore.NewCore(encoder, writeSyncer, zapcore.DebugLevel)
342//	logger := zap.New(core)
343//	defer logger.Sync()
344//
345//	logTask := func() {
346//		logger.Debug("debug...", zap.String("trace", "abcxxx"), zap.Int("id", 123), zap.Float64("pi", 3.14))
347//		logger.Info("info...", zap.String("trace", "abcxxx"), zap.Int("id", 123), zap.Float64("pi", 3.14))
348//		logger.Warn("warning...", zap.String("trace", "abcxxx"), zap.Int("id", 123), zap.Float64("pi", 3.14))
349//		logger.Error("error...", zap.String("trace", "abcxxx"), zap.Int("id", 123), zap.Float64("pi", 3.14))
350//	}
351//
352//	b.ReportAllocs()
353//	b.StartTimer()
354//
355//	for i := 0; i < b.N; i++ {
356//		logTask()
357//	}
358//}
359//
360//// go test -v ./_examples/performance_test.go -bench=^BenchmarkLogrusFile$ -benchtime=1s
361//func BenchmarkLogrusFile(b *testing.B) {
362//	file, _ := createFileOf("Z:/" + b.Name() + ".log")
363//	logger := logrus.New()
364//	logger.SetOutput(file)
365//	logger.SetLevel(logrus.DebugLevel)
366//	logger.SetFormatter(&logrus.JSONFormatter{
367//		TimestampFormat: timeFormat,
368//	})
369//
370//	logTask := func() {
371//		logger.WithFields(map[string]interface{}{"trace": "xxx", "id": 123, "pi": 3.14}).Debug("debug...")
372//		logger.WithFields(map[string]interface{}{"trace": "xxx", "id": 123, "pi": 3.14}).Info("info...")
373//		logger.WithFields(map[string]interface{}{"trace": "xxx", "id": 123, "pi": 3.14}).Warn("warning...")
374//		logger.WithFields(map[string]interface{}{"trace": "xxx", "id": 123, "pi": 3.14}).Error("error...")
375//	}
376//
377//	b.ReportAllocs()
378//	b.StartTimer()
379//
380//	for i := 0; i < b.N; i++ {
381//		logTask()
382//	}
383//}
384
Full Screen

tuned_test.go

Source: tuned_test.go Github

copy
1package performance_test
2
3import (
4	"bytes"
5	"fmt"
6
7	. "github.com/onsi/ginkgo"
8	"github.com/onsi/ginkgo/extensions/table"
9	. "github.com/onsi/gomega"
10
11	ini "gopkg.in/ini.v1"
12
13	"k8s.io/apimachinery/pkg/util/yaml"
14
15	tunedv1 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/tuned/v1"
16)
17
18var tunedYamls = []string{
19	"00-tuned-network-latency.yaml",
20	"12-tuned-worker-rt.yaml",
21}
22
23var _ = Describe("TestPerformanceTuned", func() {
24	table.DescribeTable("Tuned files should provide complete options",
25		func(fileName, isolatedCPUs, reservedCPUs string) {
26			t := loadTuned(fileName)
27			Expect(t).ToNot(BeNil())
28			validateProfiles(fileName, t)
29		},
30		// cpu params not relevant here, just use something valid
31		table.Entry(fmt.Sprintf("tuned manifest %s", tunedYamls[0]), tunedYamls[0], "1-15", "0"),
32		table.Entry(fmt.Sprintf("tuned manifest %s", tunedYamls[1]), tunedYamls[1], "1-15", "0"),
33	)
34})
35
36func loadTuned(filename string) *tunedv1.Tuned {
37	out := generateManifest(filename, "0", "0", "0", 1)
38	t := tunedv1.Tuned{}
39	err := yaml.NewYAMLOrJSONDecoder(bytes.NewBuffer(out), 1024).Decode(&t)
40	Expect(err).ToNot(HaveOccurred())
41	return &t
42}
43
44func validateProfiles(fileName string, t *tunedv1.Tuned) {
45	for _, profile := range t.Spec.Profile {
46		// caution here: Load() interprets string as file path, and []byte
47		cfg, err := ini.Load([]byte(*profile.Data))
48		Expect(err).ToNot(HaveOccurred())
49		Expect(cfg).ToNot(BeNil())
50		for _, sect := range cfg.Sections() {
51			for _, key := range sect.Keys() {
52				msg := fmt.Sprintf("error in %s:%s.%s.%s", fileName, *profile.Name, sect.Name(), key.Name())
53				val := key.Value()
54				Expect(val).NotTo(BeEmpty(), msg)
55			}
56		}
57	}
58
59}
60
Full Screen

services_command_performance_test.go

Source: services_command_performance_test.go Github

copy
1package performance_test
2
3import (
4	"fmt"
5	"os"
6	"strconv"
7
8	. "github.com/onsi/ginkgo"
9	. "github.com/onsi/gomega"
10	. "github.com/onsi/gomega/gexec"
11
12	"code.cloudfoundry.org/cli/integration/helpers"
13	"code.cloudfoundry.org/cli/integration/helpers/fakeservicebroker"
14)
15
16var _ = Describe("services command performance", func() {
17	var (
18		broker           *fakeservicebroker.FakeServiceBroker
19		currentExecution int
20		maxExecutions    = getEnvOrDefault("MAX_EXECUTIONS", 10)
21		numberOfServices = getEnvOrDefault("NUMBER_OF_SERVICE_INSTANCES", 15)
22	)
23
24	BeforeEach(func() {
25		helpers.LoginCF()
26		helpers.TargetOrgAndSpace(perfOrg, perfSpace)
27
28		currentExecution++
29		if os.Getenv("SKIP_PERF_SETUP") == "true" || currentExecution > 1 {
30			return
31		}
32
33		/* Display some useful information */
34		fmt.Printf("Number of samples (MAX_EXECUTIONS): %d\n", maxExecutions)
35		fmt.Printf("Number of service instances (NUMBER_OF_SERVICE_INSTANCES): %d\n", numberOfServices)
36
37		broker = fakeservicebroker.New().EnsureBrokerIsAvailable()
38
39		Eventually(helpers.CF("enable-service-access", broker.ServiceName())).Should(Exit(0))
40
41		for i := 0; i < numberOfServices; i++ {
42			Eventually(helpers.CF("create-service", broker.ServiceName(), broker.ServicePlanName(), fmt.Sprintf("instance-%d", i))).Should(Exit(0))
43		}
44	})
45
46	AfterEach(func() {
47		if currentExecution == maxExecutions {
48			for i := 0; i < numberOfServices; i++ {
49				Eventually(helpers.CF("delete-service", fmt.Sprintf("instance-%d", i), "-f")).Should(Exit(0))
50			}
51			broker.Destroy()
52		}
53	})
54
55	Measure("services command", func(b Benchmarker) {
56		b.Time("cf services", func() {
57			fmt.Printf("cf services...")
58			session := helpers.CF("services")
59			session.Wait()
60			fmt.Printf(" DONE.\n")
61			Expect(session).Should(Exit(0))
62		})
63	}, maxExecutions)
64})
65
66func getEnvOrDefault(key string, defaultValue int) int {
67	val, ok := os.LookupEnv(key)
68	if !ok {
69		return defaultValue
70	}
71
72	value, err := strconv.Atoi(val)
73	if err == nil {
74		return value
75	}
76	return defaultValue
77}
78
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger Name code on LambdaTest Cloud Grid

Execute automation tests with Name on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)