source: benchmark/creation/goroutine.go

Last change on this file was 50cfa99, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

change Go command-line code to behave like C

  • Property mode set to 100644
File size: 660 bytes
RevLine 
[50abab9]1package main
2
3import (
[50cfa99]4        "fmt"
5        "time"
6        "os"
7        "strconv"
[50abab9]8)
9
10var shake chan bool = make( chan bool )
11
12func noop() {
13        shake <- true   // indicate completion
14}
15
16//=======================================
17// benchmark driver
18//=======================================
19
20func main() {
[50cfa99]21        var times int = 10000000
22        if len( os.Args ) > 2 { os.Exit( 1 ) }
23        if len( os.Args ) == 2 { times, _ = strconv.Atoi(os.Args[1]) }
24
[50abab9]25        start := time.Now()
[50cfa99]26        for i := 1; i <= times; i += 1 {
[50abab9]27                go noop()               // creation
[b4107c8]28                <- shake                // wait for completion
[50abab9]29        }
30        end := time.Now()
[50cfa99]31        fmt.Printf( "%d\n", end.Sub(start) / time.Duration(times) )
[50abab9]32}
[b4107c8]33
34// Local Variables: //
35// tab-width: 4 //
36// End: //
Note: See TracBrowser for help on using the repository browser.