Skip to content

masterZSH/iorate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iorate

Reader

package yours

import (
  "github.com/masterZSH/iorate"
)

func FooFunc() {
    var buf bytes.Buffer
	for i := 0; i < 10*iorate.MB; i++ {
		buf.WriteByte(1)
	}
    // 1MB/s
	reader := iorate.NewReader(&buf, iorate.MB)
	start := time.Now()
	bf := make([]byte, 10)
	for {
		_, err := reader.Read(bf)
		if err != nil {
			break
		}
	}
	end := time.Now()
	dur := end.Sub(start) // 10s
        _, _ = end,dur
}

Writer

package yours

import (
  "github.com/masterZSH/iorate"
)

func FooFunc() {
    var buf bytes.Buffer
	// per second 1KB
	writer := iorate.NewWriter(&buf, iorate.KB)
	start := time.Now()
	for i := 0; i < 10*iorate.KB; i++ {
		_, err := writer.Write([]byte("1"))
		if err != nil {
			break
		}
	}
	end := time.Now()
	dur := end.Sub(start) // 10s
        _, _ = end,dur
}

About

io rate limiter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages