Last change
on this file since ca20b07 was
50cfa99,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
change Go command-line code to behave like C
|
-
Property mode set to
100644
|
File size:
487 bytes
|
Line | |
---|
1 | package main |
---|
2 | |
---|
3 | import ( |
---|
4 | "fmt" |
---|
5 | "time" |
---|
6 | "os" |
---|
7 | "strconv" |
---|
8 | "sync" |
---|
9 | ) |
---|
10 | |
---|
11 | var mutex sync.Mutex |
---|
12 | |
---|
13 | func call() { |
---|
14 | mutex.Lock(); |
---|
15 | mutex.Unlock(); |
---|
16 | } |
---|
17 | func main() { |
---|
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 | |
---|
22 | start := time.Now() |
---|
23 | for i := 1; i <= times; i += 1 { |
---|
24 | call(); |
---|
25 | } |
---|
26 | end := time.Now() |
---|
27 | fmt.Printf( "%d\n", end.Sub(start) / time.Duration(times) ) |
---|
28 | } |
---|
29 | |
---|
30 | // Local Variables: // |
---|
31 | // tab-width: 4 // |
---|
32 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.