Esempio n. 1
0
func measureGoRoutine(core int) {
	runtime.GOMAXPROCS(core)
	var list []int
	log := fmt.Sprintf("qsort_goroutine(%d)", core)
	common.MeasureTime(log, func() {
		list = data.GetData()
		semaphoreChannel := make(chan int)
		go qsort_goroutine(list, 0, len(list)-1, semaphoreChannel)
		for {
			<-semaphoreChannel
			break
		}
	})
	data.StoreData(list, fmt.Sprintf("qsort_goroutine(%d)_result", core))
}
Esempio n. 2
0
func measureGoRoutine_ultimate_optimization(core int) {
	runtime.GOMAXPROCS(core)
	var list []int
	log := fmt.Sprintf("qsort_goroutine_ultimate_optimization(%d)", core)
	common.MeasureTime(log, func() {
		list = data.GetData()
		count := 1
		var op int
		semaphoreChannel := make(chan int, len(list))
		go qsort_goroutine_ultimate_optimization(list, 0, len(list)-1, semaphoreChannel)
		for {
			op = <-semaphoreChannel
			count += op
			if count == 0 {
				break
			}
		}
	})
	data.StoreData(list, fmt.Sprintf("qsort_goroutine_ultimate_optimization(%d)_result", core))
}
Esempio n. 3
0
func main() {
	var list []int = data.GetData() //first time read data from disk
	common.MeasureTime("qsort_classical", func() {
		list = data.GetData()
		qsort_classical(list, 0, len(list)-1)
	})
	data.StoreData(list, "qsort_classical_result")

	for i := 1; i <= runtime.NumCPU(); i++ {
		measureGoRoutine(i)
	}

	for i := 1; i <= runtime.NumCPU(); i++ {
		measureGoRoutine_single_channel(i)
	}

	for i := 1; i <= runtime.NumCPU(); i++ {
		measureGoRoutine_ultimate_optimization(i)
	}

	fmt.Println("finished")
}