source: benchmark/readyQ/bench.go@ 91aa5ab

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 91aa5ab was 2c7eee0, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Fixed cycle benchmark to avoid extra unmatched unpark.
Added libfibre implementation.
Split out go common code into bench.go

  • Property mode set to 100644
File size: 1.6 KB
Line 
1package main
2
3import (
4 "bufio"
5 "flag"
6 "fmt"
7 "os"
8 "runtime"
9 "sync/atomic"
10 "time"
11)
12
13var clock_mode bool
14var threads_left int64
15var stop int32
16var duration float64
17var stop_count uint64
18var nprocs int
19var nthreads int
20
21func fflush(f *bufio.Writer) {
22 defer f.Flush()
23 f.Write([]byte("\r"))
24}
25
26func wait(start time.Time, is_tty bool) {
27 f := bufio.NewWriter(os.Stdout)
28 tdur := time.Duration(duration)
29 for true {
30 time.Sleep(100 * time.Millisecond)
31 end := time.Now()
32 delta := end.Sub(start)
33 if is_tty {
34 fmt.Printf(" %.1f",delta.Seconds())
35 fflush(f)
36 }
37 if clock_mode && delta >= (tdur * time.Second) {
38 break
39 } else if !clock_mode && atomic.LoadInt64(&threads_left) == 0 {
40 break
41 }
42 }
43}
44
45func bench_init() {
46 nprocsOpt := flag.Int("p", 1, "The number of processors")
47 nthreadsOpt := flag.Int("t", 1, "The number of threads")
48 durationOpt := flag.Float64("d", 0, "Duration of the experiment in seconds")
49 stopOpt := flag.Uint64("i", 0, "Duration of the experiment in iterations")
50
51 flag.Parse()
52
53 nprocs = *nprocsOpt
54 nthreads = *nthreadsOpt
55 duration = *durationOpt
56 stop_count = *stopOpt
57
58 if duration > 0 && stop_count > 0 {
59 panic(fmt.Sprintf("--duration and --iterations cannot be used together\n"))
60 } else if duration > 0 {
61 clock_mode = true
62 stop_count = 0xFFFFFFFFFFFFFFFF
63 fmt.Printf("Running for %f seconds\n", duration)
64 } else if stop_count > 0 {
65 clock_mode = false
66 fmt.Printf("Running for %d iterations\n", stop_count)
67 } else {
68 duration = 5
69 clock_mode = true
70 fmt.Printf("Running for %f seconds\n", duration)
71 }
72
73 runtime.GOMAXPROCS(nprocs)
74}
Note: See TracBrowser for help on using the repository browser.