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") }
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)) }
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)) }