fix duration of mosaic conversion#17
fix duration of mosaic conversion#17MohammadAlavi1986 wants to merge 2 commits intosausheong:masterfrom
Conversation
`t1` (end time) must be assigned to after we have received converted image from the channel
fix duration of mosaic conversion
|
I encounter this problem too. The fixed version works correctly. But I couldn't figure out the reason. Do you know anything about the reason? |
|
@hyzgh when the channel is read if the channel is not ready the receiver will be blocked until the channel is ready that's the reason why we should assign |
|
@AureaMohammadAlavi package main
import (
"fmt"
"time"
)
func getSlow() chan int {
d := make(chan int)
go func() {
time.Sleep(1*time.Second)
d <- 42
}()
return d
}
func main() {
t0 := time.Now()
m := map[string]interface{}{
"mosaic": <-getSlow(),
"duration": time.Now().Sub(t0),
}
fmt.Println(m)
}
// output: map[duration:1.000127088s mosaic:42] |
|
@hyzgh Yes it will be blocked and that's why we should only calculate the duration after we've read from the channel but in the author's code the duration is calculated (now is assigned to In your sample code you calculate duration after reading from the channel and that's correct. |
|
I got it. Thank you!
…On Fri, Jun 26, 2020 at 1:46 AM Mohammad Alavi ***@***.***> wrote:
@hyzgh <https://github.com/hyzgh> Yes it will be blocked and that's why
we should only calculate the duration after we've read from the channel but
in the author's code the duration is calculated (now is assigned to t1)
before reading from the channel.
t1 := time.Now()
images := map[string]string{
"original": originalStr,
"mosaic": <- c,
"duration": fmt.Sprintf("%v ", t1.Sub(t0)),
}
In your sample code you calculate duration after reading from the channel
and that's correct.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#17 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHN23VTUHHM4JQBSJDTIHOLRYOEPNANCNFSM4NEYBWVA>
.
--
Yuzhao
|
t1 (end time) must be assigned to after we have received converted image from the channel
mus change to: