Git Product home page Git Product logo

Comments (2)

vbauerster avatar vbauerster commented on June 16, 2024

Implementation of Ewma prefixed decorators is delegated to ewma lib. So if you decided to use it I kindly recommend to read its documentation thoroughly. If you need a quick fix I recommend to use decor.AverageSpeed instead. In your example you use ProxyWriter(io.Discard) so you could end up measuring write speed of io.Discard. By using ProxyReader instead I've got adequate results with decor.EwmaSpeed. Try io example with following patch:

diff --git a/_examples/io/main.go b/_examples/io/main.go
index 252a967..eeae8d9 100644
--- a/_examples/io/main.go
+++ b/_examples/io/main.go
@@ -11,8 +11,20 @@ import (
 )
 
 func main() {
-	var total int64 = 1024 * 1024 * 500
-	reader := io.LimitReader(rand.Reader, total)
+	var total int64 = 64 * 1024 * 1024
+
+	r, w := io.Pipe()
+
+	go func() {
+		for i := 0; i < 1024; i++ {
+			_, err := io.Copy(w, io.LimitReader(rand.Reader, 64*1024))
+			if err != nil {
+				panic(err)
+			}
+			time.Sleep(time.Second / 10)
+		}
+		w.Close()
+	}()
 
 	p := mpb.New(
 		mpb.WithWidth(60),
@@ -27,12 +39,12 @@ func main() {
 		mpb.AppendDecorators(
 			decor.EwmaETA(decor.ET_STYLE_GO, 30),
 			decor.Name(" ] "),
-			decor.EwmaSpeed(decor.SizeB1024(0), "% .2f", 30),
+			decor.EwmaSpeed(decor.SizeB1024(0), "% .2f", 60),
 		),
 	)
 
 	// create proxy reader
-	proxyReader := bar.ProxyReader(reader)
+	proxyReader := bar.ProxyReader(r)
 	defer proxyReader.Close()
 
 	// copy from proxyReader, ignoring errors

from mpb.

jtolio avatar jtolio commented on June 16, 2024

Hmm, I'm surprised that whether you use ProxyReader or ProxyWriter makes a difference - does this mean that the Proxy measurements are starting and also stopping clocks that only run during the Read or Write call? How might I reliably obtain the overall io.Copy speed, considering that either the Reader or Writer might be slow?

from mpb.

Related Issues (20)

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.