Best Ginkgo code snippet using performance_test.Clear
performance_suite_test.go
Source:performance_suite_test.go
...61 Path: path,62 OldCachePath: oldCachePath,63 }64}65func (m GoModCacheManager) Clear() {66 cmd := exec.Command("go", "clean", "-modcache")67 session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)68 Ω(err).ShouldNot(HaveOccurred())69 Eventually(session).Should(gexec.Exit(0))70}71func (m GoModCacheManager) Cleanup() {72 m.Clear()73 if m.OldCachePath == "" {74 os.Unsetenv("GOMODCACHE")75 } else {76 os.Setenv("GOMODCACHE", m.OldCachePath)77 }78}79/* PerformanceFixtureManager manages fixture data */80type PerformanceFixtureManager struct {81 TmpDir string82}83func NewPerformanceFixtureManager(tmpDir string) PerformanceFixtureManager {84 err := os.MkdirAll(tmpDir, 0700)85 Ω(err).ShouldNot(HaveOccurred())86 return PerformanceFixtureManager{87 TmpDir: tmpDir,88 }89}90func (f PerformanceFixtureManager) Cleanup() {91 Ω(os.RemoveAll(f.TmpDir)).Should(Succeed())92}93func (f PerformanceFixtureManager) MountFixture(fixture string, subPackage ...string) {94 src := filepath.Join("_fixtures", fixture+"_fixture")95 dst := filepath.Join(f.TmpDir, fixture)96 if len(subPackage) > 0 {97 src = filepath.Join(src, subPackage[0])98 dst = filepath.Join(dst, subPackage[0])99 }100 f.copyIn(src, dst)101}102func (f PerformanceFixtureManager) copyIn(src string, dst string) {103 Expect(os.MkdirAll(dst, 0777)).To(Succeed())104 files, err := os.ReadDir(src)105 Expect(err).NotTo(HaveOccurred())106 for _, file := range files {107 srcPath := filepath.Join(src, file.Name())108 dstPath := filepath.Join(dst, file.Name())109 if file.IsDir() {110 f.copyIn(srcPath, dstPath)111 continue112 }113 srcContent, err := os.ReadFile(srcPath)114 Ω(err).ShouldNot(HaveOccurred())115 Ω(os.WriteFile(dstPath, srcContent, 0666)).Should(Succeed())116 }117}118func (f PerformanceFixtureManager) PathTo(pkg string, target ...string) string {119 if len(target) == 0 {120 return filepath.Join(f.TmpDir, pkg)121 }122 components := append([]string{f.TmpDir, pkg}, target...)123 return filepath.Join(components...)124}125/* GoModDownload runs go mod download for a given package */126func GoModDownload(fixture string) {127 cmd := exec.Command("go", "mod", "download")128 cmd.Dir = pfm.PathTo(fixture)129 sess, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)130 Ω(err).ShouldNot(HaveOccurred())131 Eventually(sess).Should(gexec.Exit(0))132}133/* ScenarioSettings configures the test scenario */134type ScenarioSettings struct {135 Fixture string136 NumSuites int137 Recurse bool138 ClearGoModCache bool139 ConcurrentCompilers int140 ConcurrentRunners int141 CompileFirstSuiteSerially bool142 GoModDownloadFirst bool143 UseGoTestDirectly bool144 ConcurrentGoTests int145 GoTestCompileThenRunSerially bool146 GoTestRecurse bool147}148func (s ScenarioSettings) Name() string {149 out := []string{s.Fixture}150 if s.UseGoTestDirectly {151 if s.GoTestCompileThenRunSerially {152 out = append(out, "go test -c; then run (serially)")153 } else if s.GoTestRecurse {154 out = append(out, "go test ./...")155 } else {156 out = append(out, "go test")157 if s.ConcurrentGoTests == 1 {158 out = append(out, "serially")159 } else {160 out = append(out, fmt.Sprintf("run concurrently [%d]", s.ConcurrentGoTests))161 }162 }163 } else {164 if s.ConcurrentCompilers == 1 {165 out = append(out, "compile serially")166 } else {167 out = append(out, fmt.Sprintf("compile concurrently [%d]", s.ConcurrentCompilers))168 }169 if s.ConcurrentRunners == 1 {170 out = append(out, "run serially")171 } else {172 out = append(out, fmt.Sprintf("run concurrently [%d]", s.ConcurrentRunners))173 }174 if s.CompileFirstSuiteSerially {175 out = append(out, "will compile first suite serially")176 }177 if s.GoModDownloadFirst {178 out = append(out, "will go mod download first")179 }180 }181 return strings.Join(out, " - ")182}183func SampleScenarios(cache gmeasure.ExperimentCache, numSamples int, cacheVersion int, runGoModDownload bool, scenarios ...ScenarioSettings) {184 // we randomize the sample set of scenarios to try to avoid any systematic effects that emerge185 // during the run (e.g. change in internet connection speed, change in computer performance)186 experiments := map[string]*gmeasure.Experiment{}187 runs := []ScenarioSettings{}188 for _, scenario := range scenarios {189 name := scenario.Name()190 if experiment := cache.Load(name, cacheVersion); experiment != nil {191 AddReportEntry(name, experiment, Offset(1), ReportEntryVisibilityFailureOrVerbose)192 continue193 }194 experiments[name] = gmeasure.NewExperiment(name)195 AddReportEntry(name, experiments[name], Offset(1), ReportEntryVisibilityFailureOrVerbose)196 for i := 0; i < numSamples; i++ {197 runs = append(runs, scenario)198 }199 }200 rand.New(rand.NewSource(GinkgoRandomSeed())).Shuffle(len(runs), func(i, j int) {201 runs[i], runs[j] = runs[j], runs[i]202 })203 if len(runs) > 0 && runGoModDownload {204 GoModDownload("performance")205 }206 for idx, run := range runs {207 fmt.Printf("%d - %s\n", idx, run.Name())208 RunScenario(experiments[run.Name()].NewStopwatch(), run, gmeasure.Annotation(fmt.Sprintf("%d", idx+1)))209 }210 for name, experiment := range experiments {211 cache.Save(name, cacheVersion, experiment)212 }213}214func AnalyzeCache(cache gmeasure.ExperimentCache) {215 headers, err := cache.List()216 Ω(err).ShouldNot(HaveOccurred())217 experiments := []*gmeasure.Experiment{}218 for _, header := range headers {219 experiments = append(experiments, cache.Load(header.Name, header.Version))220 }221 for _, measurement := range []string{"first-output", "total-runtime"} {222 stats := []gmeasure.Stats{}223 for _, experiment := range experiments {224 stats = append(stats, experiment.GetStats(measurement))225 }226 AddReportEntry(measurement, gmeasure.RankStats(gmeasure.LowerMedianIsBetter, stats...))227 }228}229func RunScenario(stopwatch *gmeasure.Stopwatch, settings ScenarioSettings, annotation gmeasure.Annotation) {230 if settings.ClearGoModCache {231 gmcm.Clear()232 }233 if settings.GoModDownloadFirst {234 GoModDownload(settings.Fixture)235 stopwatch.Record("mod-download", annotation)236 }237 if settings.UseGoTestDirectly {238 RunScenarioWithGoTest(stopwatch, settings, annotation)239 } else {240 RunScenarioWithGinkgoInternals(stopwatch, settings, annotation)241 }242}243/* CompileAndRun uses the Ginkgo CLIs internals to compile and run tests with different possible settings governing concurrency and ordering */244func RunScenarioWithGinkgoInternals(stopwatch *gmeasure.Stopwatch, settings ScenarioSettings, annotation gmeasure.Annotation) {245 cliConfig := types.NewDefaultCLIConfig()...
fetching_dependencies_test.go
Source:fetching_dependencies_test.go
...24 pfm.MountFixture("performance")25 })26 It("runs a series of experiments with various scenarios", func() {27 SampleScenarios(cache, 8, 1, false,28 ScenarioSettings{Fixture: "performance", NumSuites: 5, ConcurrentCompilers: 1, ConcurrentRunners: 1, Recurse: true, ClearGoModCache: true},29 ScenarioSettings{Fixture: "performance", NumSuites: 5, ConcurrentCompilers: 2, ConcurrentRunners: 1, Recurse: true, ClearGoModCache: true},30 ScenarioSettings{Fixture: "performance", NumSuites: 5, ConcurrentCompilers: 4, ConcurrentRunners: 1, Recurse: true, ClearGoModCache: true},31 ScenarioSettings{Fixture: "performance", NumSuites: 5, ConcurrentCompilers: 1, ConcurrentRunners: 1, GoModDownloadFirst: true, Recurse: true, ClearGoModCache: true},32 ScenarioSettings{Fixture: "performance", NumSuites: 5, ConcurrentCompilers: 2, ConcurrentRunners: 1, GoModDownloadFirst: true, Recurse: true, ClearGoModCache: true},33 ScenarioSettings{Fixture: "performance", NumSuites: 5, ConcurrentCompilers: 4, ConcurrentRunners: 1, GoModDownloadFirst: true, Recurse: true, ClearGoModCache: true},34 ScenarioSettings{Fixture: "performance", NumSuites: 5, ConcurrentCompilers: 2, ConcurrentRunners: 1, CompileFirstSuiteSerially: true, Recurse: true, ClearGoModCache: true},35 ScenarioSettings{Fixture: "performance", NumSuites: 5, ConcurrentCompilers: 4, ConcurrentRunners: 1, CompileFirstSuiteSerially: true, Recurse: true, ClearGoModCache: true},36 )37 })38 })39 Describe("Analysis", func() {40 It("analyzes the various fetching dependencies scenarios to identify winners", func() {41 AnalyzeCache(cache)42 })43 })44})...
Clear
Using AI Code Generation
1import (2func main() {3 performance_test.Clear()4 fmt.Println("Clear method is called")5}6import (7func main() {8 performance_test.Clear()9 fmt.Println("Clear method is called")10}11import (12func main() {13 performance_test.Clear()14 fmt.Println("Clear method is called")15}16import (17func main() {18 performance_test.Clear()19 fmt.Println("Clear method is called")20}21import (22func main() {23 performance_test.Clear()24 fmt.Println("Clear method is called")25}26import (27func main() {28 performance_test.Clear()29 fmt.Println("Clear method is called")30}31import (32func main() {33 performance_test.Clear()34 fmt.Println("Clear method is called")35}36import (37func main() {38 performance_test.Clear()39 fmt.Println("Clear method is called")40}41import (42func main() {43 performance_test.Clear()44 fmt.Println("Clear method is called")45}46import (47func main() {48 performance_test.Clear()49 fmt.Println("Clear method is called")50}
Clear
Using AI Code Generation
1import (2func main() {3 p := performance_test.New()4 p.Start("key1")5 p.Start("key2")6 p.Stop("key1")7 p.Stop("key2")8 p.Clear()9}10import (11func main() {12 p := performance_test.New()13 p.Start("key1")14 p.Start("key2")15 p.Stop("key1")16 p.Stop("key2")17 p.Clear("key1")18}19import (20func main() {21 p := performance_test.New()22 p.Start("key1")23 p.Start("key2")24 p.Stop("key1")25 p.Stop("key2")26 p.Clear("key1", "key2")27}28import (29func main() {
Clear
Using AI Code Generation
1import (2func main() {3 performanceTest := performance_test.New()4 performanceTest.Start()5 performanceTest.Stop()6 performanceTest.Clear()7 fmt.Println(performanceTest.Result())8}9import (10func main() {11 performanceTest := performance_test.New()12 performanceTest.Start()13 performanceTest.Stop()14 performanceTest.Clear()15 fmt.Println(performanceTest.Result())16}17import (18func main() {19 performanceTest := performance_test.New()20 performanceTest.Start()21 performanceTest.Stop()22 performanceTest.Clear()23 fmt.Println(performanceTest.Result())24}25import (26func main() {27 performanceTest := performance_test.New()28 performanceTest.Start()29 performanceTest.Stop()30 performanceTest.Clear()31 fmt.Println(performanceTest.Result())32}33import (
Clear
Using AI Code Generation
1import (2func main() {3 perf_test := performance_test.NewPerformanceTest("Test")4 perf_test.StartTimer()5 perf_test.StopTimer()6 fmt.Println(perf_test)7}8import (9func main() {10 perf_test := performance_test.NewPerformanceTest("Test")11 perf_test.StartTimer()12 perf_test.StopTimer()13 perf_test.Clear()14 fmt.Println(perf_test)15}16PASS: Test (0.000s)17PASS: Test (0.000s)18PASS: Test (0.000s)19What is the difference between Clear() and StopTimer()?20What is the difference between StartTimer() and StartTimerWithTime()?21What is the difference between StopTimer() and StopTimerWithTime()?22What is the difference between StartTimer() and StopTimer()?23What is the difference between StartTimerWithTime() and StopTimerWithTime()?24What is the difference between StartTimer() and StartTimerWithTime()?25What is the difference between StopTimer() and StopTimerWithTime()?26What is the difference between StartTimer() and StopTimerWithTime()?27StartTimer() starts the timer and StopTimerWith
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!