source: benchmark/ctxswitch/goroutine.go @ 6e540ea

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 6e540ea was b4107c8, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

update existing benchmarks for changes to bench.h, add new benchmarks in new programming languages

  • Property mode set to 100644
File size: 731 bytes
Line 
1package main
2
3import (
4    "fmt"
5    "time"
6    "flag"
7    "runtime"
8)
9
10//=======================================
11// time context switch
12//=======================================
13
14var shake chan bool = make( chan bool )
15
16func ContextSwitch(N int) {
17        start := time.Now()
18        for i := 1; i <= N; i += 1 {
19                runtime.Gosched()
20        }
21        end := time.Now()
22        fmt.Printf("%d\n", end.Sub(start) / time.Duration(N))
23        shake <- true   // indicate completion
24}
25
26//=======================================
27// benchmark driver
28//=======================================
29
30func main() {
31        times := flag.Int( "times", 10000000, "loop iterations" )
32        go ContextSwitch( *times )              // context switch
33        <- shake
34}
35
36// Local Variables: //
37// tab-width: 4 //
38// End: //
Note: See TracBrowser for help on using the repository browser.