Giter VIP home page Giter VIP logo

bigo's Introduction

Big-O Run & Plot

Library that helps to run Big-O Experiments and plot the output

Go Report Card godoc License

Example comparing two variants

examples/ex1/main.go

package main

import (
	"time"

	"github.com/Oppodelldog/bigo"
)

func main() {
	for testName, testRunner := range map[string]Runner{
		"VariantA": {Sleep: 100},
		"VariantB": {Sleep: 200},
	} {
		bigo.
			New(
				testName,
				testRunner,
				bigo.NewArrayStepper([]float64{1, 2, 3}),
			).
			Run().
			WriteResultsToJson().
			PlotResults()
	}
}

// Runner implements TestRunner
type Runner struct {
	Sleep int
}

// Step simulated to test some logic. For simplicity it simply waits N*r.Sleep milliseconds.
func (r Runner) Step(n float64) bigo.OMeasures {
	timeStart := time.Now()

	// TODO: put your code under test here
	time.Sleep(time.Millisecond * time.Duration(r.Sleep) * time.Duration(n))

	return bigo.OMeasures{{O: float64(time.Since(timeStart).Milliseconds())}}
}
Variant A Variant B

Example extended capturing, N-2d

Let's assume you want to test every N with another subset of test values.
For example N would represent the number of Records in your database.
Now you want to test how your algorithm reacts on different user inputs.
This is why Step returns a list of measures bigo.OMeasures.
This allows to capture multiple Os for every N.
The plot the will reflect that in min, max, mean, all

Here's a sample examples/ex2/main.go

// Step simulated 3 additional scales to the given N. In this case
func (r Runner) Step(n float64) bigo.OMeasures {
   var measures bigo.OMeasures
   for i := 1; i <= 3; i++ {
   	timeStart := time.Now()
   	time.Sleep(time.Millisecond * time.Duration(r.Sleep) * time.Duration(n) * time.Duration(i*r.Factor))
   	measures = append(measures, bigo.OMeasure{O: float64(time.Since(timeStart).Milliseconds())})
   }

   return measures
}
Variant A Variant B

Example combining multiple Results in one plot

To combine mutliple capture results in one plot you have to collect the Results into a bigo.PlotSeriesList, which then can be passed to bigo.PlotTestResults to generate one plot file.

Here's a sample examples/ex3/main.go

func main() {
   seriesList := bigo.PlotSeriesList{}
   for testName, testRunner := range map[string]Runner{
   	"VariantA": {Sleep: 100, Factor: 1},
   	"VariantB": {Sleep: 200, Factor: 2},
   } {
   	seriesList = append(seriesList, bigo.PlotSeries{Name: testName, Results: bigo.
   		New(
   			testName,
   			testRunner,
   			bigo.NewArrayStepper([]float64{1, 2, 3}),
   		).
   		Run().GetResults(),
   	})
   }

   // plot the collected result data and create one plot out of the data
   bigo.PlotTestResults("A/B", seriesList)
}
Combined Plot

bigo's People

Contributors

oppodelldog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.