Code Monkey home page Code Monkey logo

chronos's Introduction

chronos

No frills, simple gathering of execution stats. This is essentially no more than a convenient wrapper for time.Since.

Has a high footprint on performance but is more sensitive and granular than Go's profiler.

Useful when you have blocks of code that don't span across functions or that execute in just a few nanoseconds.

Since Chronos has a high footprint (the "quantum" conundrum), it is best to avoid nesting Chronos's.

ChronosTS

For strong thread safety (at a cost on performance), use ChronosTS.

Examples

func main() {
	ch := chronos.Builder{}.Build()
	ch.Start()
	doSomething()
	ch.Stop()
	ch.Println("doSomething")
}

// doSomething >> c: 1 e: 1.1425ms avg: 1.1425ms

Threaded code

func TestExample1(t *testing.T) {
	coh1 := &chronos.Cohort{}

	var wg sync.WaitGroup

	for i := 1; i <= 10_000; i++ {
		c1 := chronos.Builder{}.WithSamplingRate(100).BuildTS()
		coh1.Add(c1)

		wg.Add(1)
		go func(c1 *chronos.ChronosTS) {
			defer wg.Done()
			for i := 1; i <= 1_000; i++ {
				c1.Start()
				time.Sleep(1 * time.Nanosecond)
				c1.Stop()
			}
		}(c1)
	}

	wg.Wait()

	coh1.Println("doSomething")
}

// doSomething >> c: 100000 tcd: 260.336807ms avg: 2.603µs mpt: 26.033µs

chronos's People

Contributors

seborama 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.