You can calculate the size as per Nipun Talukdar's comment.
len([]byte("YourDataHere"))
b.Len()
And use time.Now()
and time.Since()
to get the time taken.
var b bytes.Buffer
input := []byte("YourDataHere")
fmt.Println("Input size : ", len(input))
gz := gzip.NewWriter(&b)
start := time.Now()
gz.Write(input)
if _, err := gz.Flush(); err != nil {
panic(err)
}
totalTime := time.Since(start)
fmt.Println("Compressed size : ", b.Len(), "
Time taken : ", totalTime)
gz.Close()
Same method can be applied with unzipping.
You can also create a support function that can do the timing.
func timer(startTime time.Time) {
totalTime := time.Since(startTime)
log.Println("Time taken : ",totalTime)
}
Usage : defer timer(time.Now())
at the start of the function.