MCPcopy Create free account
hub / github.com/Soypete/Production-Go-Examples / main

Function main

exercise-3/solution/main.go:112–135  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

110}
111
112func main() {
113 numWorkers := flag.Int("workers", 1, "number of workers")
114 cpuprofile := flag.String("cpuprofile", "", "write cpu profile to `file`")
115 memprofile := flag.String("memprofile", "", "write memory profile to `file`")
116
117 flag.Parse()
118 startTime := time.Now()
119
120 // run pprof
121 runPprof(*cpuprofile, *memprofile)
122
123 workerPool := &workerPool{
124 wg: new(sync.WaitGroup),
125 msgs: make(chan string),
126 numWorkers: *numWorkers,
127 mu: new(sync.Mutex),
128 }
129
130 // start the workers in the background and wait for data on the channel
131 // we already know the number of workers, we can increase the WaitGroup once
132 go workerPool.queueMessages()
133 numWords := workerPool.run()
134 fmt.Printf("Number of words: %d\nTime to process file: %2f seconds", numWords, time.Since(startTime).Seconds())
135}

Callers

nothing calls this directly

Calls 3

queueMessagesMethod · 0.95
runMethod · 0.95
runPprofFunction · 0.70

Tested by

no test coverage detected