Esempio n. 1
0
func GetFibo(i int) fibo.F {
	f := fibo.F{}
	f.Seed = i
	f.Calc()
	time.Sleep(100 * time.Millisecond)
	return f
}
Esempio n. 2
0
func main() {
	iteration := 100
	fmt.Println("T1 - Go Routine")

	tstart := time.Now()
	for i := 0; i < iteration; i++ {
		go func() {
			f := fibo.F{}
			f.Seed = i
			f.Calc()
			fmt.Printf("Fibo of %d is %d \n", f.Seed, f.Result)
			time.Sleep(100 * time.Millisecond)
		}()
	}

	fmt.Printf("Done. Completed in %v \n", time.Since(tstart))
}
Esempio n. 3
0
func main() {
	iteration := 100
	fmt.Println("T3 - WaitGroup")

	tstart := time.Now()
	wg := new(sync.WaitGroup)
	for i := 0; i < iteration; i++ {
		wg.Add(1)
		go func(i int, wg *sync.WaitGroup) {
			f := fibo.F{}
			f.Seed = i
			f.Calc()
			fmt.Printf("Fibo of %d is %d \n", f.Seed, f.Result)
			time.Sleep(100 * time.Millisecond)
			wg.Done()
		}(i, wg)
	}
	wg.Wait()

	fmt.Printf("Done. Completed in %v \n", time.Since(tstart))
}