source: benchmark/readyQ/bench.go@ 03ecdcf

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 03ecdcf was f4f79dd, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Minor clean-up in benchmarks

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