package main

import (
    "fmt"
    "time"
    "flag"
    "runtime"
)

//=======================================
// time context switch
//=======================================

var shake chan bool = make( chan bool )

func ContextSwitch(N int) {
	start := time.Now()
	for i := 1; i <= N; i += 1 {
		runtime.Gosched()
	}
	end := time.Now()
	fmt.Printf("%d\n", end.Sub(start) / time.Duration(N))
	shake <- true   // indicate completion
}

//=======================================
// benchmark driver
//=======================================

func main() {
	times := flag.Int( "times", 10000000, "loop iterations" )
	go ContextSwitch( *times )		// context switch
	<- shake
}

// Local Variables: //
// tab-width: 4 //
// End: //
