Changeset 50cfa99


Ignore:
Timestamp:
Jan 9, 2020, 5:06:29 PM (22 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
arm-eh, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
51493a4, 6b6a3b8
Parents:
c93fd72
Message:

change Go command-line code to behave like C

Location:
benchmark
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • benchmark/creation/goroutine.go

    rc93fd72 r50cfa99  
    22
    33import (
    4     "fmt"
    5     "time"
    6     "flag"
     4        "fmt"
     5        "time"
     6        "os"
     7        "strconv"
    78)
    89
     
    1819
    1920func main() {
    20         times := flag.Int( "times", 500000, "loop iterations" )
    21         flag.Parse()
     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
    2225        start := time.Now()
    23         for i := 1; i <= *times; i += 1 {
     26        for i := 1; i <= times; i += 1 {
    2427                go noop()               // creation
    2528                <- shake                // wait for completion
    2629        }
    2730        end := time.Now()
    28         fmt.Printf( "%d\n", end.Sub(start) / time.Duration(*times) )
     31        fmt.Printf( "%d\n", end.Sub(start) / time.Duration(times) )
    2932}
    3033
  • benchmark/ctxswitch/goroutine.go

    rc93fd72 r50cfa99  
    22
    33import (
    4     "fmt"
    5     "time"
    6     "flag"
    7     "runtime"
     4        "fmt"
     5        "time"
     6        "os"
     7        "strconv"
     8        "runtime"
    89)
    910
     
    2930
    3031func main() {
    31         times := flag.Int( "times", 10000000, "loop iterations" )
    32         go ContextSwitch( *times )              // context switch
     32        var times int = 10000000
     33        if len( os.Args ) > 2 { os.Exit( 1 ) }
     34        if len( os.Args ) == 2 { times, _ = strconv.Atoi(os.Args[1]) }
     35        go ContextSwitch( times )               // context switch
    3336        <- shake
    3437}
  • benchmark/mutex/goroutine.go

    rc93fd72 r50cfa99  
    22
    33import (
    4     "fmt"
    5     "time"
    6     "flag"
    7     "sync"
     4        "fmt"
     5        "time"
     6        "os"
     7        "strconv"
     8        "sync"
    89)
    910
     
    1112
    1213func call() {
    13     mutex.Lock();
    14     mutex.Unlock();
     14        mutex.Lock();
     15        mutex.Unlock();
    1516}
    1617func main() {
    17         times := flag.Int( "times", 10000000, "loop iterations" )
    18         flag.Parse()
     18        var times int = 10000000
     19        if len( os.Args ) > 2 { os.Exit( 1 ) }
     20        if len( os.Args ) == 2 { times, _ = strconv.Atoi(os.Args[1]) }
     21
    1922        start := time.Now()
    20         for i := 1; i <= *times; i += 1 {
     23        for i := 1; i <= times; i += 1 {
    2124                call();
    2225        }
    2326        end := time.Now()
    24         fmt.Printf( "%d\n", end.Sub(start) / time.Duration(*times) )
     27        fmt.Printf( "%d\n", end.Sub(start) / time.Duration(times) )
    2528}
    2629
Note: See TracChangeset for help on using the changeset viewer.