Junior
// What will the following program output and how long will it run? package main import ( "fmt" "time" ) const numRequests = 10_000 var count int func networkRequest() { time.Sleep(time.Millisecond) // Emulating a network request. count++ } func main() { for i := 0; i < numRequests; i++ { networkRequest() } fmt.Println(count) // 10_000 }
sobes.tech AI
Answer from AI
The program will perform 10,000 iterations, each calling the networkRequest() function, which pauses for 1 millisecond (emulating a network request) and increments the global variable count by 1.
The program output will be:
10000
The execution time will be approximately 10,000 milliseconds, or about 10 seconds, since the networkRequest() calls are sequential, each delayed by 1 ms.
If the requests were executed in parallel (for example, using goroutines), the time could be significantly reduced.